Re: Function Misbehaving
| From: | Jochem Maas | Date: | Thu, 23 Nov 2006 15:12:30 +0000 |
| Subject: | Re: Function Misbehaving | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-245092@lists.php.net to get a copy of this message | ||
Beginners beware ... small, potential head-fryer coming up...
Richard Lynch wrote:
> I personally would use is_null($url) to test if it was NULL.
>
> isset() is not the weapon of choice for that, imho...
>
> No idea if that will "fix it" as I've never tried to use isset() to
> test for NULL and have no idea what it does.
occasionally we need to eat our own dogfood Richard (i.e. test stuff) :-) ...
php -r '$a = null; $b = array(null); var_dump(isset($a), isset($b[0]));'
which is not helpful to the beginner because setting $a to NULL means $a is not set,
counter-intuitive to say the least :-) but we both know this is not going to change.
BUT even when it's not set it kind of is ...
php -r '
error_reporting(E_ALL);
$a = null; var_dump(isset($a), $a);
var_dump(isset($b), $b);
'
niether $a nor $b are set but $a is still more set than $b. are you confused? :-)
I guess is_null() is the weapon of choice here!