Electronics & Programming

develissimo

Open Source electronics development and programming

  • You are not logged in.
  • Root
  • » PHP
  • » Detecting if a null variable exists? [RSS Feed]

#1 June 11, 2010 18:43:49

Brian M.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Detecting if a null variable exists?


Is it just me or are we missing a way in the language to check if avariable that has been set to NULL exists or not?is_null() on an unset variable throws a NOTICE.
$var === null throws a notice.

So, you have to use isset()? But, ah,

$var = null;
if(isset($var))

yields false.Is array_key_exists("var", $GLOBALS) the only solution to this problem?Seems silly.perhaps an var_exists() function is needed to fill this hole?

--

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

Offline

#2 June 14, 2010 07:47:13

Michael W.
Registered: 2009-11-02
Reputation: +  0  -
Profile   Send e-mail  

Detecting if a null variable exists?


On 06/11/2010 07:43 PM, Brian Moon wrote:Is it just me or are we missing a way in the language to check if a
variable that has been set to NULL exists or not?
...
perhaps an var_exists() function is needed to fill this hole?php -r 'function f(){$f=null; var_dump(array_key_exists("f",
get_defined_vars()));} f();'



Mike

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

Offline

  • Root
  • » PHP
  • » Detecting if a null variable exists? [RSS Feed]

Board footer

Moderator control

Enjoy the 18th of October
PoweredBy

The Forums are managed by develissimo stuff members, if you find any issues or misplaced content please help us to fix it. Thank you! Tell us via Contact Options
Leave a Message
Welcome to Develissimo Live Support