note 90782 added to function.is-null

From: Date: Sat, 09 May 2009 16:38:43 +0000
Subject: note 90782 added to function.is-null
Groups: php.notes 
Request: Send a blank email to php-notes+get-154390@lists.php.net to get a copy of this message
[Note. A manipulation error has caused submission of incomplete/bogus versions of my note.] A small but important difference between "is_null" and "isset" is the following: "is_null" tests if an *expression* (not a *variable*) is null, while "isset" tests if a *variable* has null value or is undefined. The difference is manifested in the two following experiments: Experiment 1: <?php function test() { return null; } var_dump(is_null(test())); // displays "true" var_dump(isset(test())); // parse error, because "test()" is not a variable ?> Experiment 2: <?php error_reporting(E_ALL); var_dump(isset($an_undefined_variable)); // displays "false" since "$an_undefined_variable" is not defined var_dump(is_null($an_undefined_variable)); // displays "true" (as expected), but throws a notice because "$an_undefined_variable" is not defined. ?> ---- Server IP: 89.31.146.176 Probable Submitter: 213.103.152.224 ---- Manual Page -- http://www.php.net/manual/en/function.is-null.php Edit -- https://master.php.net/note/edit/90782 Del: integrated -- https://master.php.net/note/delete/90782/integrated Del: useless -- https://master.php.net/note/delete/90782/useless Del: bad code -- https://master.php.net/note/delete/90782/bad+code Del: spam -- https://master.php.net/note/delete/90782/spam Del: non-english -- https://master.php.net/note/delete/90782/non-english Del: in docs -- https://master.php.net/note/delete/90782/in+docs Del: other reasons-- https://master.php.net/note/delete/90782 Reject -- https://master.php.net/note/reject/90782 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#154390) next »