#29446 [Opn->Csd]: PHP 5 allows class constants to be overriden
| From: | tony2001@php.net | Date: | Fri, 25 Feb 2005 19:39:46 +0000 |
| Subject: | #29446 [Opn->Csd]: PHP 5 allows class constants to be overriden | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-74589@lists.php.net to get a copy of this message | ||
ID: 29446
Updated by: tony2001@php.net
Reported By: dimo dot vanchev at bianor dot com
-Status: Open
+Status: Closed
Bug Type: Zend Engine 2 problem
Operating System: Windows 2000
PHP Version: 5.0.3
Assigned To: tony2001
New Comment:
Yes, it was fixed only in HEAD (i.e. 5.1.0-dev), as this change can
affect some existing scripts.
Previous Comments:
------------------------------------------------------------------------
[2005-02-25 14:59:56] dimo dot vanchev at bianor dot com
This bug doesn't seem to be fixed in 5.0.3 version, at least for the
Windows version.
I haven't tryed to reproduce this bug under Linux for 5.0.3 version
yet.
------------------------------------------------------------------------
[2004-09-24 09:51:07] dimo dot vanchev at bianor dot com
seems to work fine now,
great many thanks for improving PHP's quality
best regards
------------------------------------------------------------------------
[2004-09-10 15:12:15] tony2001@php.net
I mean FIXED in CVS, try latest snapshots.
------------------------------------------------------------------------
[2004-09-10 15:11:12] tony2001@php.net
Please try using this CVS snapshot:
http://snaps.php.net/php5-latest.tar.gz
For Windows:
http://snaps.php.net/win32/php5-win32-latest.zip
------------------------------------------------------------------------
[2004-07-29 17:56:54] dimo dot vanchev at bianor dot com
Description:
------------
If we declare a class constant twice or more PHP allows this without
any notifications. This should be fixed, because it may bring to
confusion. A constant should be constant, thus not allowing to be
overriden neither in the same class, nor in child classes.
Currently non-class constants allow to be overriden too, at least they
output a notice saying "Constant already defined". Maybe this should be
brought up to warning.
Just my thoughts!
Reproduce code:
---------------
<?php
class A {
const MY_CONSTANT = "A. value_1";
const MY_CONSTANT = "A. value_2";
public function __construct() {
echo self::MY_CONSTANT, "\n";
}
}
class B extends A {
const MY_CONSTANT = "B. value_1";
const MY_CONSTANT = "B. value_2";
public function __construct() {
echo self::MY_CONSTANT, "\n";
}
}
new A();
new B();
?>
Expected result:
----------------
should display warning, error or something like that.
Actual result:
--------------
A. value_2
B. value_2
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=29446&edit=1