On Sep 16, 2015, at 06:44, Rowan Collins <rowan.coll...@gmail.com> wrote:
> 
> Can you give an example of code where you do not know this until the code 
> runs - i.e. where "is this variable set?" is something you can hang business 
> logic on?
> 
> Somewhere where it would make sense to write something like this, if the 
> exists() function were available for plain variables:
> 
> if ( exists($a) ) {
> ...
> } elseif ( is_null($a) ) {
> ...
> } else {
> ...
> }

Sure. It’s not common with controlling business logic (fortunately), but it is 
very common in error-handling code. I already mentioned the templates, but an 
even more common scenario is config files that are supposed to just define a 
bunch of standalone variables, which is a very common pattern. If you’re 
writing code that relies on those variables, or you’re writing the code that’s 
supposed to pull that file in to begin with, it’s smart to make sure all the 
variables actually got set, and if not, display an error to the user to go fix 
the config. Sometimes, isset() works for this if combined with a null check, 
but it fails in cases where null is an acceptable value.

-Bob

Attachment: signature.asc
Description: Message signed with OpenPGP using GPGMail

Reply via email to