Posted by Oliver Grδtz on 05/25/07 00:04
Luigi schrieb:
> Hi to all,
> I' d like to know if exists some sentences like this one below (in
> java) for PHP:
>
> JAVA:
> boolean isNull = (myObj == null) ? true : false;
Ignoring that this makes no sense since the expression in the
parantheses already yields a boolean value, I assume you are looking for
a PHP documentation of the ternary operator (which is not a Java
invention but has its roots in good old C). Here you are:
http://de.php.net/manual/en/language.operators.comparison.php#language.operators.comparison.ternary
If you want to be sure that the result of your expression is of a
certain type (since you put a "boolean" at the beginning of the line and
PHP does not have strict typing), you can add a cast to the desired type:
$isNull = (bool) ($myObj==null) ? true : false;
Of course you are triple ensuring what can be accomplished by the PHP
engine internal function:
$isNull = is_null($myObj);
*g*
OLLi
--
Sidney: "Are you sure you don't wanna stay for dinner."
Eric: "I'd love to but... I gotta save the world."
[Alias 402]
[Back to original message]
|