#18125 [Opn->Csd]: Cannot use :: operator when defining child classes

From: Date: Sun, 01 Jun 2003 17:31:30 +0000
Subject: #18125 [Opn->Csd]: Cannot use :: operator when defining child classes
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-40827@lists.php.net to get a copy of this message
ID: 18125 Updated by: helly@php.net Reported By: optikSmoke at subdimension dot com -Status: Open +Status: Closed Bug Type: Zend Engine 2 problem Operating System: Linux 2.4.18 (RedHat 7.3) PHP Version: 5.0.0-dev New Comment: PHP5 doesn't support nested classes. Previous Comments: ------------------------------------------------------------------------ [2003-04-18 17:39:17] thekid at thekid dot de As namespaces have been rewritten entierly since this bug was reported, I think what's still left of this is: namespace foo { class bar { } } $name= 'foo::bar'; $o= new $name(); Results in: Fatal error: Class 'foo::bar' not found eval('$o= new '.$name.'();'); is ugly but works. ------------------------------------------------------------------------ [2002-07-04 01:14:52] bob at bravenet dot com The problem exists in the internal handling of :: within classnames. Here is another example of the same problem in a different context. In this case...when using the classname within a variable, PHP isnt able to find the class. <? class App { function CreateObject($classname) { return new $classname; } } class App::Client { function __construct() { echo 'In App::Client constructor'; } } class Client { function __construct() { echo 'In Client constructor'; } } App::CreateObject('Client'); App::CreateObject('App::Client'); ?> ------------------------------------------------------------------------ [2002-07-02 23:41:11] optikSmoke at subdimension dot com Essentially, I have run into this problem: I am unable to use the '::' operator to define a class within a namespace or inherit from a class within another namespace (I am using 4.3.0-alpha2). Example: <? class Boo { class Scream { } } class Boo::Ahh extends Boo::Scream { } ?> This will generate a "expecting ''{'' on line 7" parser error (the "class Boo::Ahh ....." line). Similarly, "class Biff extends Boo::Scream {}" and "class Biff::Ahh extends Boo {}" (or any other definitions in these forms) will generate the same error. It appears to me that any class definitions that use the :: operator and the extends clause will generate this error. I have found this to be a problem that is particularly annoying, as I am developing a set of library classes that reside within specific namespaces, in seperate files. For example, I would like to be able to create a namespace "Foo" containing class "Bar" and its child class "Biff", both in seperate files so scripts not utililizing "Biff" need not load it. ------------------------------------------------------------------------ -- Edit this bug report at http://bugs.php.net/?id=18125&edit=1

« previous php.bugs (#40827) next »