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

isset surprise

P: n/a
rw
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
Jul 17 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
On Wed, 26 Jan 2005 21:20:01 +0100, rw <rw***@gazeta.pl> wrote:
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?


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 / <an**@andyh.co.uk> / <http://www.andyh.co.uk>
<http://www.andyhsoftware.co.uk/space> Space: disk usage analysis tool
Jul 17 '05 #2

P: n/a
"rw" <rw***@gazeta.pl> wrote in message
news:ct**********@nemesis.news.tpi.pl...
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


Hmmm...interesting. 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.
Jul 17 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.