-
Notifications
You must be signed in to change notification settings - Fork 121
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
global constant vs. class constant #2
Comments
No, that is clearly a bug. |
After a cursory inspection I think the issue actually may lie upstream in the pdepend AST ... or at least how phpdox is interacting with it. I'm actually not entirely sure what the expected behavior should be, but I suspect it should be evaluating the constant and storing that in the XML. |
OK, so I have tracked it to here: https://github.com/manuelpichler/staticReflection/blob/master/src/main/php/pdepend/reflection/parser/Parser.php#L1296 If you run phpdox against the following folder in the Joomla Platform: https://github.com/joomla/joomla-platform/tree/master/libraries/joomla/log you can see the problem in action. Essentially in the static reflection parser the result of defined(JLog::ALL) or any of the other constants is coming back false. I'm not really sure why that would be, but in the 20 minutes I played around with it I was unsuccessful in figuring out how to get those values. Hope that helps. |
It is already logged: https://www.pivotaltracker.com/story/show/9356191 |
I've been talking to Manuel about that issue a few times. Hence his ticket :) We so far didn't fully agree though on what the actual expected behaviour in my context (==phpdox) vs. the expected behaviour in a Reflection API would be: From a documentation point of view it might be nice to have the actual value but it's probably more important to know the constant name since usually nobody uses the real value anyway as it is an implementation detail of the defining class. On the other hand in an static reflection, there might not even be code available to resolve the constant in question. Any recommendation from your perspective? |
It is a good question actually. From my point of view the most valuable piece of information is in fact the constant name, not it's value as you pointed out. The whole point of constants to me is to not have to specifically care about what the value is. That being said, I can see where the static reflection API might be equally if not more interested in the value. Using the example above, assuming self::DETECT has a value of 1: <parameter name="type" optional="true" byreference="false">
<default>'__StaticReflectionConstantValue(self::DETECT)'</default>
</parameter> I would rather see it look like: <parameter name="type" optional="true" byreference="false" value="1">
<default>self::DETECT</default>
</parameter> In the case where the constant cannot be resolved just leave out the value attribute. Ideally that wouldn't ever happen, but it would provide a stop gap for the time being since you will always have the actual constant name throughout parsing. |
I like that approach - comes close to what I had in mind already - and I guess i'll try to talk Manuel into providing support like that. Until that happens, I'll probably just hack around the string and strip out the |
Fixed with a workaround by @LouisLandry in commit 32102ca |
The error_get_last function returns NULL if there hasn't been an error yet, Says from from https://secure.php.net/error_get_last. PHP Fatal error: Uncaught TypeError: Return value of TheSeer\phpDox\ErrorHandler::getLastError() must be of the type array, null returned in /net/enterprise-data1/home/ad min/gasolwu/Code/phpdox/src/shared/ErrorHandler.php:147 Stack trace: #0 /net/enterprise-data1/home/admin/gasolwu/Code/phpdox/src/shared/ErrorHandler.php(55): TheSeer\phpDox\ErrorHandler->getLastError() theseer#1 [internal function]: TheSeer\phpDox\ErrorHandler->handleShutdown() theseer#2 {main} thrown in /net/enterprise-data1/home/admin/gasolwu/Code/phpdox/src/shared/ErrorHandler.php on line 147
The error_get_last function returns NULL if there hasn't been an error yet, And the exit status 255 is reserved by PHP and shall be used when fatal error occurred. PHP Fatal error: Uncaught TypeError: Return value of TheSeer\phpDox\ErrorHandler::getLastError() must be of the type array, null returned in /net/enterprise-data1/home/ad min/gasolwu/Code/phpdox/src/shared/ErrorHandler.php:147 Stack trace: #0 /net/enterprise-data1/home/admin/gasolwu/Code/phpdox/src/shared/ErrorHandler.php(55): TheSeer\phpDox\ErrorHandler->getLastError() theseer#1 [internal function]: TheSeer\phpDox\ErrorHandler->handleShutdown() theseer#2 {main} thrown in /net/enterprise-data1/home/admin/gasolwu/Code/phpdox/src/shared/ErrorHandler.php on line 147 References: - https://secure.php.net/exit - https://secure.php.net/error_get_last
An optional method parameter with a constant as default value (e.g.
SORT_ASC
) will result inbut if it is using a class constant like
self::DETECT
it will result inIs this the expected behavior?
The text was updated successfully, but these errors were encountered: