Edit report at https://bugs.php.net/bug.php?id=63976&edit=1
ID: 63976
Patch added by: mike@php.net
Reported by: don at smugmug dot com
Summary: Parent class incorrectly using child constant in
class property
Status: Assigned
Type: Bug
Package: Class/Object related
Operating System: Ubuntu 12.04
PHP Version: 5.4.10
Assigned To: dmitry
Block user comment: N
Private report: N
New Comment:
The following patch has been added/updated:
Patch Name: zend_do_fetch_constant
Revision: 1363687163
URL: https://bugs.php.net/patch-display.php?bug=63976&patch=zend_do_fetch_constant&revision=1363687163
Previous Comments:
------------------------------------------------------------------------
[2013-03-18 13:09:52] dmitry@php.net
I understood the problem and your patch, I also agree what it fixes the problem for this particular
case.
Unfortunately, I afraid that it may break some applications, because it may make constant resolution
early in the moment, when such constants were not defined yet. For example your patch is going to
break the following script.
<?php
class A {
public $x = X;
}
class B extends A {
}
const X = 1;
$b = new B;
var_dump($b);
?>
I think the problem may be solved by substituting "self" and "parent" by actual
class names at compile-time. It must be quite easy to do it for "self" (in
zend_do_fetch_constant or in zend_do_declare_property), but not so easy for "parent" (we
may use CG(parent_class_name) to solve it).
------------------------------------------------------------------------
[2013-03-14 17:42:39] don at smugmug dot com
I have validated that the patch solves our use case (and the test case in this
bug). Thanks Mike!
------------------------------------------------------------------------
[2013-03-14 09:01:59] mike@php.net
@dmitry, can you have a look at the , please?
The condition could actually be simplified to
if (ce->type == ZEND_USER_CLASS) ...
Thank you.
------------------------------------------------------------------------
[2013-02-14 17:30:36] mike@php.net
The following patch has been added/updated:
Patch Name: update_class_constants
Revision: 1360863036
URL: https://bugs.php.net/patch-display.php?bug=63976&patch=update_class_constants&revision=1360863036
------------------------------------------------------------------------
[2013-01-12 03:53:33] don at smugmug dot com
'Have a preference' should have said 'I have a preference'. Certainly not
intending for PHP to add some new INI option or something to change how static::
and self:: behave. :)
Also, have confirmed this on 5.4.4 and CentOS in addition to Ubuntu and 5.4.10,
both with and without extensions like APC loaded.
------------------------------------------------------------------------
The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
https://bugs.php.net/bug.php?id=63976--
Edit this bug report at https://bugs.php.net/bug.php?id=63976&edit=1