isset surprise

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

    isset surprise

    In php 5.0.3 i found that
    $s="a";
    if(isset($s->prop))
    echo "surprise";

    In previous php it was false;
    Is it bug?
    --
    Rob Was
  • Andy Hassall

    #2
    Re: isset surprise

    On Wed, 26 Jan 2005 21:20:01 +0100, rw <rwas8@gazeta.p l> wrote:
    [color=blue]
    >In php 5.0.3 i found that
    >$s="a";
    >if(isset($s->prop))
    >echo "surprise";
    >
    >In previous php it was false;
    >Is it bug?[/color]

    Looks like one, it's certainly inconsistent. Consider:

    andyh@server:~/public_html$ cat test2.php
    <?php
    $s="a";
    var_dump($s->prop);
    echo isset($s->prop) ? "surprise1\ n" : "no surprise1\n";

    $x = NULL;
    var_dump($x);
    echo isset($x) ? "surprise2\ n" : "no surprise2\n";

    $y = $s->prop;
    var_dump($y);
    echo isset($y) ? "surprise3\ n" : "no surprise3\n";
    ?>
    andyh@server:~/public_html$ php -q test2.php

    Notice: Trying to get property of non-object in
    /home/andyh/public_html/test2.php on line 3
    NULL
    surprise1
    NULL
    no surprise2

    Notice: Trying to get property of non-object in
    /home/andyh/public_html/test2.php on line 10
    NULL
    no surprise3

    --
    Andy Hassall / <andy@andyh.co. uk> / <http://www.andyh.co.uk >
    <http://www.andyhsoftwa re.co.uk/space> Space: disk usage analysis tool

    Comment

    • Chung Leong

      #3
      Re: isset surprise

      "rw" <rwas8@gazeta.p l> wrote in message
      news:ct8uav$4hr $1@nemesis.news .tpi.pl...[color=blue]
      > In php 5.0.3 i found that
      > $s="a";
      > if(isset($s->prop))
      > echo "surprise";
      >
      > In previous php it was false;
      > Is it bug?
      > --
      > Rob Was[/color]

      Hmmm...interest ing. Seems to suggest that there's an alternate universe of
      sort existing within the string.

      empty() exhibits the same effect. Somehow "$s->prop" is being translated to
      "$s{0}" inside isset(). If the string begins with "0", then isset() returns
      false.


      Comment

      Working...