note 83650 added to language.operators.comparison

From: Date: Fri, 06 Jun 2008 01:06:54 +0000
Subject: note 83650 added to language.operators.comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-140160@lists.php.net to get a copy of this message
@jescribens at urbangolem dot com <?php var_dump($x); //can be null if($x[0][0]['value'] < 1) ?> 'If the function returns null then you get "nok" printed.' Around here that sort of code would get you smacked. First, it's very unstable. Once fixed so that $something and $other had values, it would still print "nok" if $x[0][0]['value'] existed but contained the value zero, or indeed anything other than a number that's at least one. More importantly, if you want to check to see if something is null, wouldn't it be smarter (and certainly more self-explanatory) to check to see if it null instead of some random property that may or may not have anything to do with what you're wanting to check? <?php $x = myfunction(); if(is_null($x)) // or if($x===null) { echo 'nok'; } else { echo 'ok'; } ---- Server IP: 203.89.181.186 Probable Submitter: 202.27.216.35 ---- Manual Page -- http://www.php.net/manual/en/language.operators.comparison.php Edit -- https://master.php.net/note/edit/83650 Del: integrated -- https://master.php.net/note/delete/83650/integrated Del: useless -- https://master.php.net/note/delete/83650/useless Del: bad code -- https://master.php.net/note/delete/83650/bad+code Del: spam -- https://master.php.net/note/delete/83650/spam Del: non-english -- https://master.php.net/note/delete/83650/non-english Del: in docs -- https://master.php.net/note/delete/83650/in+docs Del: other reasons-- https://master.php.net/note/delete/83650 Reject -- https://master.php.net/note/reject/83650 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#140160) next »