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

 ID:                 53202
 Comment by:         agent_harris at secure-mail dot biz
 Reported by:        agent_harris at secure-mail dot biz
 Summary:            unexpected return value getConstant
 Status:             Wont fix
 Type:               Feature/Change Request
 Package:            Reflection related
 Operating System:   Ubuntu Linux 9.04
 PHP Version:        5.3.3
 Block user comment: N

 New Comment:

hmm, ok the situation regarding NULL values i have obviously overseen.



the question is imho not how trivial it is to wrap it (sure using
getConstants is an option). but why is throwing an exception not an
option. it is what any other good language or library would do. but if
it has something to do with compatibility for legacy code then maybe it
should be considered in previous php versions to introduce something
like a "strict option" for newer code. otherwise new functionality will
always get wrapped.


Previous Comments:
------------------------------------------------------------------------
[2010-10-29 17:17:47] ras...@php.net

I don't see how returning NULL helps here.  You can just as easily have
defined 

the constant to be NULL.  There is no value we can return that is not
definable, 

and throwing an exception isn't an option.



You have 2 ways to check it further if you do get false back.  

defined('class::constant') will tell you if it is defined and
ReflectionClass 

::getConstants() will give you an array of all the defined constants
along with 

their values.  It is trivial to wrap this and throw your own exception
if the 

constant isn't defined.

------------------------------------------------------------------------
[2010-10-29 15:51:29] agent_harris at secure-mail dot biz

Description:
------------
to make it short:



if you try to get the value of a constant via
ReflectionClass::getConstant(...) and the constant name you specified
does not exist, the function returns bool(false).



but maybe you have really defined a constant as bool(false). then you
are not able to distinguish between these two possibilities.



in that case the preferred behavior should be to throw and exception or
return the null value. 



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



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

Reply via email to