Bug #63976 [Csd]: Parent class incorrectly using child constant in class property
| From: | dmitry@php.net | Date: | Tue, 19 Mar 2013 13:06:25 +0000 |
| Subject: | Bug #63976 [Csd]: Parent class incorrectly using child constant in class property | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-177892@lists.php.net to get a copy of this message | ||
Edit report at https://bugs.php.net/bug.php?id=63976&edit=1
ID: 63976
Updated by: dmitry@php.net
Reported by: don at smugmug dot com
Summary: Parent class incorrectly using child constant in
class property
Status: Closed
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 fix for this bug has been committed.
Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
For Windows:
http://windows.php.net/snapshots/
Thank you for the report, and for helping us make PHP better.
Previous Comments:
------------------------------------------------------------------------
[2013-03-19 13:05:49] dmitry@php.net
Automatic comment on behalf of dmitry@zend.com
Revision: http://git.php.net/?p=php-src.git;a=commit;h=7b0993bfb4b19bb160a72310b907c4fc12a5bef9
Log: Fixed bug #63976 (Parent class incorrectly using child constant in class property)
------------------------------------------------------------------------
[2013-03-19 12:35:21] mike@php.net
Reflection is also affected.
...and I couldn't come up with code yet, where parent:: is problematic.
------------------------------------------------------------------------
[2013-03-19 10:00:45] mike@php.net
Unfortunately, this also changes error messages to something like:
Undefined class constant 'Foo::B' instead of 'self::B'...
------------------------------------------------------------------------
[2013-03-19 09:59:23] mike@php.net
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
------------------------------------------------------------------------
[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).
------------------------------------------------------------------------
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