[NEW] - from Java to PHP

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Luigi

    [NEW] - from Java to PHP

    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

  • Schraalhans Keukenmeester

    #2
    Re: [NEW] - from Java to PHP

    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.

    Comment

    • Toby A Inkster

      #3
      Re: [NEW] - from Java to PHP

      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

      Comment

      • =?ISO-8859-1?Q?Oliver_Gr=E4tz?=

        #4
        Re: [NEW] - from Java to PHP

        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:



        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]

        Comment

        Working...