On 15/07/2011, at 1:58 PM, Daevid Vincent wrote:
> 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;
> }
> }
In both cases, $v is equivalent to false, so is_string(NULL) = false == NULL ==
$v, likewise for is_null($v);
You're most likely after switch(true) { … } rather than switch($v)
---
Simon Welsh
Admin of http://simon.geek.nz/
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php