Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can you have nested classes in PHP?

Tags:

oop

php

class

I'm not talking about inheritance. And I'm not talking about nested objects. I'm talking:

System::Web::Templating(...)

kind of nesting. These are classes of which you shouldn't create instances.. so...

like image 675
aviraldg Avatar asked Oct 10 '09 15:10

aviraldg


3 Answers

No.

However, you could do something like this by returning an instantiated object in getInstance():

myClass::getInstance()->foo();
like image 87
Mike B Avatar answered Nov 11 '22 09:11

Mike B


nope, you can’t nest classes in php. see: http://bytes.com/topic/php/answers/10138-nested-classes-php

like image 30
knittl Avatar answered Nov 11 '22 08:11

knittl


It seems that you're speaking about namespaces, not about any kind of nesting. This feature was implemented in PHP 5.3, and is documented here.

like image 39
Ignas R Avatar answered Nov 11 '22 08:11

Ignas R