Edit report at http://bugs.php.net/bug.php?id=44568&edit=1

 ID:                 44568
 Comment by:         philip dot preisser at web dot de
 Reported by:        andrea at 3site dot it
 Summary:            class name as defined constant
 Status:             Open
 Type:               Feature/Change Request
 Package:            Feature/Change Request
 Operating System:   Windows XP
 PHP Version:        5.2.6RC3
 Block user comment: N
 Private report:     N

 New Comment:

Test2 Fatal error: Class 'Test2' not found in
/var/www/HTTP/devel/current/frameworld/test.php on line 53


Previous Comments:
------------------------------------------------------------------------
[2008-03-30 10:59:12] andrea at 3site dot it

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.


------------------------------------------------------------------------



-- 
Edit this bug report at http://bugs.php.net/bug.php?id=44568&edit=1

Reply via email to