|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2004-09-10 15:11 UTC] tony2001@php.net
[2004-09-10 15:12 UTC] tony2001@php.net
[2004-09-24 09:51 UTC] dimo dot vanchev at bianor dot com
[2005-02-25 14:59 UTC] dimo dot vanchev at bianor dot com
[2005-02-25 20:39 UTC] tony2001@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 07:00:01 2025 UTC |
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