#29446 [Csd]: PHP 5 allows class constants to be overriden
| From: | dimo dot vanchev at bianor dot com | Date: | Fri, 24 Sep 2004 07:51:10 +0000 |
| Subject: | #29446 [Csd]: PHP 5 allows class constants to be overriden | ||
| References: | 1 | Groups: | php.bugs |
| Request: | Send a blank email to php-bugs+get-66626@lists.php.net to get a copy of this message | ||
ID: 29446
User updated by: dimo dot vanchev at bianor dot com
Reported By: dimo dot vanchev at bianor dot com
Status: Closed
Bug Type: Zend Engine 2 problem
Operating System: RedHat 9.0
PHP Version: 5.0.0
Assigned To: tony2001
New Comment:
seems to work fine now,
great many thanks for improving PHP's quality
best regards
Previous Comments:
------------------------------------------------------------------------
[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