Support for php inner classes

Are there any versions of PHP 5.3 or after supporting inner classes? Example:

class MyClass{ class PrivateClass1{ } class PrivateClass2{ } class PrivateClass3{ } private $obj1; private $obj2; private $obj3; __construct(){ $obj1 = new PrivateClass1(); $obj2 = new PrivateClass2(); $obj3 = new PrivateClass3(); } } 
+8
php
source share
2 answers

PHP (5.4.3) does not currently support Inner / Friend classes

And there is also no RFC on the wiki asking to add such a feature.

+13
source share

You can create a class within a specific class, but you cannot define a class in a class definition. Thus, this means that your design is not valid.

But you can always extend the class with another class, check this URL more:

http://php.net/manual/en/keyword.extends.php

Check Can I instantiate a PHP class inside another class? even more.

+2
source share

All Articles