php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #43138 Allow keywords self and parent in dynamic class references
Submitted: 2007-10-30 11:36 UTC Modified: 2007-11-01 21:10 UTC
Votes:2
Avg. Score:3.0 ± 0.0
Reproduced:1 of 2 (50.0%)
Same Version:0 (0.0%)
Same OS:1 (100.0%)
From: felipensp at gmail dot com Assigned: colder (profile)
Status: Wont fix Package: Feature/Change Request
PHP Version: 5.3 OS: Linux
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2007-10-30 11:36 UTC] felipensp at gmail dot com
Description:
------------
'self' and 'parent' don't are evaluated when calling static member/method with class name in variables.

Reproduce code:
---------------
<?php

class foo {
  const foo = 1;
  public function __construct() {    
    $classname = 'parent';
    echo $classname::FOO;
    // Fatal error: Class 'parent' not found
    
    $classname = 'self';
    echo $classname::FOO;
    // Fatal error: Class 'self' not found 
    
    // new $classname; too
  }
}

new foo;

Actual result:
--------------
Fatal error: Class 'parent' not found

and

Fatal error: Class 'self' not found 

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-10-30 20:07 UTC] colder@php.net
This behavior is consistent with the old one: new $classname is also available in version prior to 5.3, and works the same way.

self and parent are keywords, not real class names. Hence I reclassify this report as a feature request.
 [2007-11-01 21:10 UTC] colder@php.net
After some discussions, keywords won't be allowed in dynamic class references. It will be documented accordingly.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri May 17 09:01:32 2024 UTC