Re: PHP 7.1 - Address PHPSadness #28?
| From: | Robert Williams | Date: | Wed, 16 Sep 2015 17:27:47 +0000 |
| Subject: | Re: PHP 7.1 - Address PHPSadness #28? | ||
| References: | 1 2 3 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-88251@lists.php.net to get a copy of this message | ||
On Sep 16, 2015, at 06:44, Rowan Collins <rowan.collins@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: [application/pgp-signature] Message signed with OpenPGP using GPGMail signature.asc
Attachment: [application/pgp-signature] Message signed with OpenPGP using GPGMail signature.asc