John Davidson

PHP - Nested class with a same name


In PHP, is it possible to have a nested class with a same name ? Tried searching a lot for these, but did not found any solution.

My Answer:
No, it is not possible to have a nested class with the same name in PHP. Each class in PHP must have a unique name within its namespace. Having nested classes with the same name would lead to ambiguity and confusion in the code. If you need to have multiple classes with the same name, you should consider using namespaces to differentiate them.

Rate this post

4 of 5 based on 7279 votes


© 2024 - Personal Blogs Platform. All Rights Reserved.
Create blog  |  Privacy Policy  |  Terms & Conditions  |  Contact Us