PDA

View Full Version : nested classes?



JohnN
July 20th, 2008, 11:48
ok, so you can't do this:

class hello{

function wo(){

class yo{

}

}
}

but if you do

class hello{

function wo(){

include_once("class.php");

}
}

if class.php is a class.

could someone explain this to me please?

themoose
July 20th, 2008, 11:55
I think it's because once class.php has been parsed, it's no longer a class in the workings, but a seperate defined class - wheras in the first situation the class is an undefined class within the class that can only be called through the parent class.

Very confusing situation though, what I said may have been absolute gubbins.

krakjoe
July 21st, 2008, 04:58
In php < 5.3, classes are defined in the global scope. No matter where you call include the class will be defined in the global scope.

You cannot nest classes, you can however nest functions inside methods / functions. Nested functions are also declared in the global scope.

In php > 5.3, this might change. You still won't be able to nest classes, but you may be able to include classes in the current namespace, this is untested ...

Why are you trying to do all of this anyway, there might be a better way ??

JohnN
July 21st, 2008, 05:48
Long story, I'm messing around with abstract classes, there's a good chance I'll get stuck so you'll see then ;)

thanks for the explanations guys.

stuffradio
July 23rd, 2008, 03:42
Well you can extend classes... and you can have supers.

What do you want to do with it?