php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #29647 self:: into child class seems to refer to parent class
Submitted: 2004-08-13 12:17 UTC Modified: 2004-08-14 12:47 UTC
From: mrpyle at libero dot it Assigned:
Status: Not a bug Package: Class/Object related
PHP Version: 5.* OS: *
Private report: No CVE-ID: None
 [2004-08-13 12:17 UTC] mrpyle at libero dot it
Description:
------------
self:: into child class seems to refer to parent class, is this a bug?

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

abstract class ParentClass
{

  static public function modifyStaticProp($propName, $propValue)
  {
  
      self::${$propName} = $propValue ;

  }

}

class ChildClass extends ParentClass
{

   static public $a ;
   static public $b ;

}


ChildClass::modifyStaticProp('a', 'some value') ;




?>

Expected result:
----------------
ChildClass::$a == 'some value' ;

Actual result:
--------------
Fatal error: Access to undeclared static property: ParentClass::$a in c:\phproot\static\bug.php5 on line 9

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-08-13 19:26 UTC] helly@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

self is bound at compile time.
 [2004-08-14 10:11 UTC] mrpyle at libero dot it
Could you explain yourself better please?

If this isn't a bug IMHO it is a wrong/not desiderable behaviour:

self:: should refer to the current class and parent:: to the parent class, if not this means that you cannot apply inheritance to classes containing static members
 [2004-08-14 12:47 UTC] helly@php.net
It does.

abstract class ParentClass
{

  static public function modifyStaticProp($propName, $propValue)
  {
  
      self::${$propName} = $propValue ;

  }

}

There is only one class, the class itself, aka ParentClass.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Mon Sep 28 13:01:23 2020 UTC