note 110806 deleted from language.operators.comparison by aharvey

From: Date: Tue, 11 Dec 2012 01:50:23 +0000
Subject: note 110806 deleted from language.operators.comparison by aharvey
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-192449@lists.php.net to get a copy of this message
Note Submitter: hckurniawan at gmail dot com ---- 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

« previous php.notes (#192449) next »