By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,009 Members | 1,643 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,009 IT Pros & Developers. It's quick & easy.

[NEW] - from Java to PHP

P: n/a
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;

PHP:
$isNull = ???????????????;

Can someone help me please?

Thanks in advance, Luigi

May 24 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
At Thu, 24 May 2007 06:00:04 -0700, Luigi let his monkeys type:
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;

PHP:
$isNull = ???????????????;

Can someone help me please?

Thanks in advance, Luigi
$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;

HTH
Sh.
May 24 '07 #2

P: n/a
Luigi wrote:
JAVA:
boolean isNull = (myObj == null) ? true : false;
That's a particularly poor piece of Java. How about:

boolean isNull = (myObj==null);
PHP:
$isNull = ???????????????;
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
http://tobyinkster.co.uk/blog/2007/05/22/wifi-scare/
May 24 '07 #3

P: n/a
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...arison.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]
May 25 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.