Robert Williams wrote on 16/09/2015 18:06:
As an example, go back to template systems that just define a bunch of variables within the view’s scope: the view code needs to verify that it actually got needed variables before it uses them so that it can fail gracefully if it didn't.

At first sight, that seems reasonably sensible. But the more I think about it, the less convinced I am that exists() is what is needed there.

Firstly, if the template can cope gracefully with a null value, it seems like it could just cope with missing variables the same way.

Secondly, if the intention is to alert the programmer that the Controller is buggy and not passing the expected data, then wrapping everything in an exists() check seems somewhat bloated. PHP will already raise a notice if you try to access the variable (just use is_null() in place of isset() where appropriate), and the rendering logic could use register_error_handler() to capture those. That mechanism isn't that pretty, but neither would a template be that was constantly worrying if variables existed.

If there's an *expected* condition where the Controller won't pass all the variables to the template, then we're back to the argument that that condition should be explicitly signalled, rather than relying on unset-ness as an extra piece of metadata.

Regards,
--
Rowan Collins
[IMSoP]

--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to