note 90780 added to function.is-null

From: Date: Sat, 09 May 2009 16:07:44 +0000
Subject: note 90780 added to function.is-null
Groups: php.notes 
Request: Send a blank email to php-notes+get-154388@lists.php.net to get a copy of this message
A small but important difference between "is_null" and "empty" is the following: "is_null" tests if an *expression* is null, while "empty" tests if a *variable* is defined and has not a null value. 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(empty(test()); // parse error, because "test()" is not a variable ?> Experiment 2: <?php error_reporting(E_ALL); var_dump(empty($an_undefined_variable)); // displays "true" since "$an_undefined_variable" is not defined var_dump(is_null($an_undefined_variable)); // displays "true", 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/90780 Del: integrated -- https://master.php.net/note/delete/90780/integrated Del: useless -- https://master.php.net/note/delete/90780/useless Del: bad code -- https://master.php.net/note/delete/90780/bad+code Del: spam -- https://master.php.net/note/delete/90780/spam Del: non-english -- https://master.php.net/note/delete/90780/non-english Del: in docs -- https://master.php.net/note/delete/90780/in+docs Del: other reasons-- https://master.php.net/note/delete/90780 Reject -- https://master.php.net/note/reject/90780 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#154388) next »