note 72508 added to function.empty

From: Date: Mon, 22 Jan 2007 10:08:36 +0000
Subject: note 72508 added to function.empty
Groups: php.notes 
Request: Send a blank email to php-notes+get-122032@lists.php.net to get a copy of this message
I wanted to correct a couple of errors in some earlier user notes, regarding which is better, using empty() within an if clause to be evaluated, or using only the variable. E.g.: if (!$blah) versus if (empty($blah)) or if ($blah) versus if (!empty($blah)) First, one person noted that empty() is basically worthless because you don't need it to do the above functionality. However, I think this is wrong for 2 reasons: 1. It is needed for arrays and (I think) objects 2. empty() is actually FASTER than using just the variable. You might think that it would be slower because it looks like a function, but it is actually a language construct. Apparently it is optimized. It is at least 10% faster, sometimes nearly 20% faster. Second, one person claimed that if you don't use empty, and just test the variable, you will get an E_WARNING error. I don't know if this used to be true, but for me in PHP 5.2, it only generates an E_NOTICE. I hope this clears up somebody's confusion. ---- Server IP: 216.194.113.175 Probable Submitter: 68.163.200.198 ---- Manual Page -- http://www.php.net/manual/en/function.empty.php Edit -- https://master.php.net/note/edit/72508 Del: integrated -- https://master.php.net/note/delete/72508/integrated Del: useless -- https://master.php.net/note/delete/72508/useless Del: bad code -- https://master.php.net/note/delete/72508/bad+code Del: spam -- https://master.php.net/note/delete/72508/spam Del: non-english -- https://master.php.net/note/delete/72508/non-english Del: in docs -- https://master.php.net/note/delete/72508/in+docs Del: other reasons-- https://master.php.net/note/delete/72508 Reject -- https://master.php.net/note/reject/72508 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#122032) next »