phug-php / phug

Phug - The Pug Template Engine for PHP
https://phug.selfbuild.fr
MIT License
62 stars 3 forks source link

Support objects that implement __toBoolean in conditions/loops #61

Closed kylekatarnls closed 4 years ago

kylekatarnls commented 4 years ago

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: