PHP Nested classes work... sort of?
Posted
by SeanJA
on Stack Overflow
See other posts from Stack Overflow
or by SeanJA
Published on 2010-04-09T14:53:30Z
Indexed on
2010/04/09
15:03 UTC
Read the original article
Hit count: 316
So, if you try to do a nested class like this:
//nestedtest.php
class nestedTest{
function test(){
class E extends Exception{}
throw new E;
}
}
You will get an error Fatal error: Class declarations may not be nested in [...]
but if you have a class in a separate file like so:
//nestedtest2.php
class nestedTest2{
function test(){
include('e.php');
throw new E;
}
}
//e.php
class E Extends Exception{}
So, why does the second hacky way of doing it work, but the non-hacky way of doing it does not work?
© Stack Overflow or respective owner