Reputation: 335
I have a piece of code:
$data = array();
$data['foo'] = 'tst';
$data['bar'] = array('asd');
$data['user'] = new stdClass();
var_dump(isset($data->foo));
Now i have executed the code on two environments.
First:
PHP 5.2.6-1+lenny16 with Suhosin-Patch 0.9.6.2 (cli) (built: Feb 3 2012 08:19:55)
Copyright (c) 1997-2008 The PHP Group
Zend Engine v2.2.0, Copyright (c) 1998-2008 Zend Technologies
with Xdebug v2.2.4, Copyright (c) 2002-2014, by Derick Rethan
Second:
PHP 5.3.2-1ubuntu4.24 with Suhosin-Patch (cli) (built: Apr 4 2014 02:25:37)
Copyright (c) 1997-2009 The PHP Group
Zend Engine v2.3.0, Copyright (c) 1998-2010 Zend Technologies
with Xdebug v2.2.5, Copyright (c) 2002-2014, by Derick Rethans
On the first i got as result bool(true)
but on the second bool(false)
.
I've read the migration guide (php.net), but there was nothing to find about this behavior.
Can anyone explain me this behavior?
Note:
If i change the code to
var_dump(isset($data['foo']))
i get the same result on both.
Upvotes: 0
Views: 113
Reputation: 522015
As you can see here, the behaviour changed between 5.2.11 and 5.2.12. The release notes for 5.2.12 refer to bug #50255 isset() and empty() silently casts array to object
having been fixed.
So, it was a bug in older versions.
Upvotes: 2