is_null() and is_string() reversed when using in switch case statements...

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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]
 */
?>


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux