Closed ajcrites closed 11 years ago
I would like to fix this issue myself, but I haven't contributed to this project before. My suggestions would be to do either one of the following:
TalesInternal
method for writing functions that checks against the constants returns null
for NOTHING_KEYWORD
and possibly throws an exception for DEFAULT_KEYWORD
.
true:default
would use the actual default value to perform the expression, but I'm not sure if it's available at that time, or if this is even desired.Also it may be preferable to use methods rather than functions for phptal_
, but this is most likely a separate issue.
Another possible method would be to check against a match of _NOTHING_NOTHING...
within the string before the expression is returned, but I think that is much uglier.
Thanks for spotting this. I think you've got a good idea what the problem is — I'll be happy to merge a fix if you write one.
How about replacing nothing keyword with an instance of a class that stringifies to null?
class PHPTAL_NothingKeyword {
function __toString() {return 'null';}
}
This way It'd work when it's treated as a string, but you could check for its special status with instanceof
.
PHPTAL/Php/TalesInternal
was updated to return function calls as strings at some point, but this can lead to unintended expressions when the default/nothing keywords are used.For example, any of the following:
....and many others will yield notices such as:
Undefined constant _NOTHING_NOTHING_NOTHING_NOTHING_
This is because the evaluation of
true:
,not:
,json:
, etc. now returns a string like:This is what
convertExpressionToExpressions
,TalesChainExecutor::_executeChain
, and other methods receive. Many of these methods have exact checks againstPHPTAL_Php_TalesInternal::NOTHING_KEYWORD
(and DEFAULT), but these will fail against the above expressions.