aviraldg
aviraldg

Reputation: 9154

Can you have nested classes in PHP?

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...

Upvotes: 11

Views: 7226

Answers (3)

Ignas R
Ignas R

Reputation: 3409

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.

Upvotes: 2

Mike B
Mike B

Reputation: 32145

No.

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

myClass::getInstance()->foo();

Upvotes: 7

knittl
knittl

Reputation: 265151

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

Upvotes: 2

Related Questions