is_null() and is_string() reversed when using in switch case statements...
| From: | Daevid Vincent | Date: | Fri, 15 Jul 2011 01:58:40 +0000 |
| Subject: | is_null() and is_string() reversed when using in switch case statements... | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-314086@lists.php.net to get a copy of this message | ||
Can someone double check me here, but I think I found a bug...
<?php
/*
$ php -v
PHP 5.3.6 with Suhosin-Patch (cli) (built: Apr 28 2011 14:20:48)
Copyright (c) 1997-2011 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2011 Zend Technologies
with Xdebug v2.0.5, Copyright (c) 2002-2008, by Derick Rethans
*/
function test($v)
{
var_dump($v);
if (is_string($v)) echo "FOUND A STRING.\n";
if (is_null($v)) echo "FOUND A NULL.\n";
switch ($v)
{
case is_string($v):
echo "I think v is a string, so this is broken.\n";
break;
case is_null($v):
echo "I think v is null, so this is broken.\n";
break;
case is_object($v):
$v = '{CLASS::'.get_class($v).'}';
echo "I think v is a class $v\n";
break;
case is_bool($v):
$v = ($v) ? '{TRUE}' : '{FALSE}';
echo "I think v is boolean $v\n";
break;
case is_array($v):
$v = '['.implode(',',$v).']';
echo "I think v is an array $v\n";
break;
case is_numeric($v):
echo "I think v is a number $v\n";
break;
}
}
class SomeClass {}
test('');
test(null);
test(new SomeClass());
test(true);
test(69);
test(array(1,2,3,4,5));
/*
Output will be:
string '' (length=0)
FOUND A STRING. I think v is null, so this is broken.
null
FOUND A NULL. I think v is a string, so this is broken.
object(SomeClass)[1]
I think v is a class {CLASS::SomeClass}
boolean true
I think v is boolean {TRUE}
int 69
I think v is a number 69
array
0 => int 1
1 => int 2
2 => int 3
3 => int 4
4 => int 5
I think v is an array [1,2,3,4,5]
*/
?>