[NEW] - from Java to PHP

Do you have a question? Post it now! No Registration Necessary.  Now with pictures!

Threaded View
Hi to all,
I' d like to know if exists some sentences like this one below (in
java) for PHP:

boolean isNull = (myObj == null) ? true : false;

$isNull = ???????????????;

Can someone help me please?

Thanks in advance, Luigi

Re: [NEW] - from Java to PHP

At Thu, 24 May 2007 06:00:04 -0700, Luigi let his monkeys type:

Quoted text here. Click to load it

$isNull = ($myObj === null) ? true : false;

== asserts A has the same value as B (implicit cast if required/possible)
=== asserts A has the same type and value as B (no cast)
$A = true;
$B = 1;
if ($A == $B) => true;
if ($A === $B) => false;


Re: [NEW] - from Java to PHP

Luigi wrote:

Quoted text here. Click to load it

That's a particularly poor piece of Java. How about:

    boolean isNull = (myObj==null);

Quoted text here. Click to load it

You could use almost the same piece of code in PHP:

    $isNull = ($myObj===NULL);

or slightly better:

    $isNull = is_null($myObj);

In general, I think you'll find that PHP and Java's syntaxes have more
similarities than differences, owing to the fact that they both were
strongly influenced by C in syntax.

Coming back to your original question, no I don't know of any, though
Google knows of a few pages comparing PHP syntax with Ruby.

Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 89 days, 21:14.]

                        The Great Wi-Fi Controversy

Re: [NEW] - from Java to PHP

Luigi schrieb:
Quoted text here. Click to load it

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:


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);



Sidney: "Are you sure you don't wanna stay for dinner."
Eric: "I'd love to but... I gotta save the world."
[Alias 402]

Site Timeline