note 98820 added to types.comparisons

From: Date: Fri, 09 Jul 2010 14:47:00 +0000
Subject: note 98820 added to types.comparisons
Groups: php.notes 
Request: Send a blank email to php-notes+get-170824@lists.php.net to get a copy of this message
I make some tests and, obviously, is_null() is a long function... //Starting expression : Expression : $a= ""; //Keys code 0 for if(!empty()) 1 for if(!$a) 2 for if(!isset()) 3 for if(!is_null()) 4 for if($a!=NULL) 5 for if($a!==NULL) for 1000 iterations : Test #1 : Array ( [0] => 0.0297870635986 [1] => 0.0290060043335 [2] => 0.0300090312958 [3] => 0.0368828773499 [4] => 0.0322570800781 [5] => 0.0322999954224 ) Test #2 : Array ( [0] => 0.029853105545 [1] => 0.0290319919586 [2] => 0.0301752090454 [3] => 0.037113904953 [4] => 0.0324239730835 [5] => 0.0322329998016 ) Test #3 : Array ( [0] => 0.0297608375549 [1] => 0.0289840698242 [2] => 0.030063867569 [3] => 0.0371332168579 [4] => 0.0321879386902 [5] => 0.0322639942169 ) Test #4 : Array ( [0] => 0.0298280715942 [1] => 0.0289750099182 [2] => 0.0300970077515 [3] => 0.0369868278503 [4] => 0.0322008132935 [5] => 0.0322051048279 ) Test #5 : Array ( [0] => 0.0298631191254 [1] => 0.0289449691772 [2] => 0.0301380157471 [3] => 0.0370509624481 [4] => 0.0321509838104 [5] => 0.0322020053864 ) Test #6 : Array ( [0] => 0.0297420024872 [1] => 0.0288641452789 [2] => 0.0300099849701 [3] => 0.0368599891663 [4] => 0.0321710109711 [5] => 0.0321891307831 ) Test #7 : Array ( [0] => 0.0300168991089 [1] => 0.0289509296417 [2] => 0.0300140380859 [3] => 0.0368049144745 [4] => 0.0322518348694 [5] => 0.0322649478912 ) Test #8 : Array ( [0] => 0.0297529697418 [1] => 0.0290191173553 [2] => 0.0300440788269 [3] => 0.0368709564209 [4] => 0.0323839187622 [5] => 0.0322561264038 ) Test #9 : Array ( [0] => 0.0297918319702 [1] => 0.0289509296417 [2] => 0.0300209522247 [3] => 0.0368239879608 [4] => 0.0321390628815 [5] => 0.0321969985962 ) Test #10 : Array ( [0] => 0.0297689437866 [1] => 0.0289649963379 [2] => 0.030081987381 [3] => 0.0367720127106 [4] => 0.0321559906006 [5] => 0.0322380065918 ) So, in order ASC, the ranking is 1st : if($a) (or opposite) 2nd : if(empty($a)) (or opposite) 3rd : if(isset($a)) (or opposite) 4th : if($a === NULL) (or opposite) 5th : if($a == NULL) (or opposite) 6th : if(is_null($a)) (or opposite) Of course, I know that those lines don't produice the same result... Just use the good one for what you want ! (e.g. if you want that a variable $a can be (bool)false, prefer use if(!$a) than if($a === false), while your $a is declared before...) ---- Server IP: 69.147.83.197 Probable Submitter: 85.116.42.193 ---- Manual Page -- http://www.php.net/manual/en/types.comparisons.php Edit -- https://master.php.net/note/edit/98820 Del: integrated -- https://master.php.net/note/delete/98820/integrated Del: useless -- https://master.php.net/note/delete/98820/useless Del: bad code -- https://master.php.net/note/delete/98820/bad+code Del: spam -- https://master.php.net/note/delete/98820/spam Del: non-english -- https://master.php.net/note/delete/98820/non-english Del: in docs -- https://master.php.net/note/delete/98820/in+docs Del: other reasons-- https://master.php.net/note/delete/98820 Reject -- https://master.php.net/note/reject/98820 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#170824) next »