Observed:
Third-party libraries that can be used as expression/code handlers (like js-phpize) may pass object that actually represent a other value Phug may try to cast as string (for output) or as boolean (for conditions/loops). While we may rely to __toString native PHP feature for the first case to be handled properly, such feature does not exist for boolean (second case).
Expected:
When Phug know a given expression will be used as boolean (if, elseif, while), it might help the user and/or third-parti libraries to prepare this expression for a boolean usage.
Solution proposal:
Support objects that implement __toBoolean in conditions/loops by default.
Allow to extend conditions with custom transformation to change the way to check a value is truthy
(and so optionally remove/change/extend the __toBoolean support).
Relates to https://github.com/BKWLD/laravel-pug/issues/82 and https://github.com/pug-php/js-phpize/issues/33
Observed: Third-party libraries that can be used as expression/code handlers (like js-phpize) may pass object that actually represent a other value Phug may try to cast as string (for output) or as boolean (for conditions/loops). While we may rely to
__toString
native PHP feature for the first case to be handled properly, such feature does not exist for boolean (second case).Expected: When Phug know a given expression will be used as boolean (if, elseif, while), it might help the user and/or third-parti libraries to prepare this expression for a boolean usage.
Solution proposal:
__toBoolean
in conditions/loops by default.__toBoolean
support).