|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2010-12-01 07:50 UTC] philip dot preisser at web dot de
[2010-12-22 13:35 UTC] johannes@php.net
-Status: Open
+Status: Bogus
-Package: Feature/Change Request
+Package: *General Issues
[2010-12-22 13:35 UTC] johannes@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 03:00:01 2025 UTC |
Description: ------------ It seems to be an ambiguity issue and a probable future problem. You can create a class and define a constant with the same name and vice-versa. Who is the class and who is the constant? For future problems: currently, the magic __toString method works as magic instance method even if it is declared as public static ( ... and inherited in instances as public without static ... but this is another problem ... ) If one day PHP would like to support a public static __toString method this ambiguity will be a problem to understand if we are trying to get them, or the possible defined constant. Reproduce code: --------------- class Test{} define('Test', 123); // defined('Test') or class_exists('Test') ? define('Test2', 'Test2'); class Test2{} get_class(new Test2) === Test2; // true echo Test2; // Test2 $ref = Test2; new $ref; // an instanceof Test2 ... is_string(Test2); // true Expected result: ---------------- A fatal error, because a constant should be a unique and immutable value with a name that could not be used as class one and a class should be unique as well (if we cannot use the same name for two different classes, how can we have two totally different meaning with a sngle name, the class and the constant) Actual result: -------------- It is possible to create a class and then define a constant with the same name, and it is possible to define a constant and then a class with the same name.