php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #18125 Cannot use :: operator when defining child classes
Submitted: 2002-07-02 23:41 UTC Modified: 2003-06-01 12:31 UTC
Votes:5
Avg. Score:4.2 ± 1.0
Reproduced:3 of 3 (100.0%)
Same Version:2 (66.7%)
Same OS:2 (66.7%)
From: optikSmoke at subdimension dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 5.0.0-dev OS:
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: optikSmoke at subdimension dot com
New email:
PHP Version: OS:

 

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

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2002-07-04 01:14 UTC] 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');

?>
 [2003-04-18 17:39 UTC] 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.
 [2003-06-01 12:31 UTC] helly@php.net
PHP5 doesn't support nested classes.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Wed Dec 03 03:00:01 2025 UTC