|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2002-07-02 23:41 UTC] 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.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Wed Dec 03 02:00:01 2025 UTC |
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'); ?>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.