note 110806 added to language.operators.comparison

From: Date: Mon, 10 Dec 2012 23:35:42 +0000
Subject: note 110806 added to language.operators.comparison
Groups: php.notes 
Request: Send a blank email to php-notes+get-192447@lists.php.net to get a copy of this message
There is a bug/feature in PHP where where comparing any string starting with _ (underscores) to 0 resulting in a TRUE. [~]$ php --version PHP 5.3.3-7+squeeze14 with Suhosin-Patch (cli) (built: Aug 6 2012 14:18:06) Copyright (c) 1997-2009 The PHP Group Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies with Suhosin v0.9.32.1, Copyright (c) 2007-2010, by SektionEins GmbH [~]$ php -r "var_dump('_blank' == 0);" bool(true) [~]$ php -r "var_dump('_some_otherstring1' == 0);" bool(true) A work around for this is to do 2 comparisons: var_dump(!is_numeric($variable) && '_blank' == $variable); [~]$ php -a Interactive shell php > $variable = 0; php > var_dump(!is_numeric($variable) && '_blank' == $variable); bool(false) php > exit ---- Server IP: 69.147.83.199 Probable Submitter: 72.52.91.2 (proxied: 149.135.146.109) ---- Manual Page -- http://php.net/manual/en/language.operators.comparison.php Edit -- https://master.php.net/note/edit/110806 Del: integrated -- https://master.php.net/note/delete/110806/integrated Del: useless -- https://master.php.net/note/delete/110806/useless Del: bad code -- https://master.php.net/note/delete/110806/bad+code Del: spam -- https://master.php.net/note/delete/110806/spam Del: non-english -- https://master.php.net/note/delete/110806/non-english Del: in docs -- https://master.php.net/note/delete/110806/in+docs Del: other reasons-- https://master.php.net/note/delete/110806 Reject -- https://master.php.net/note/reject/110806 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#192447) next »