php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #50255 isset() and empty() silently casts array to object
Submitted: 2009-11-21 10:08 UTC Modified: 2009-11-24 21:54 UTC
From: tyra3l at gmail dot com Assigned: felipe
Status: Closed Package: Scripting Engine problem
PHP Version: 5.*, 6 OS: *
Private report: No CVE-ID:
 [2009-11-21 10:08 UTC] tyra3l at gmail dot com
Description:
------------
If you try to check the existence of a property on an array, suprisingly you wont get any error or notice, but you will get the results as you were checking with the correct type.

Reproduce code:
---------------
<?php
$a = array('foo' => 'bar');
echo "<pre>";var_dump(isset($a->foo));echo "</pre>";
echo "<pre>";var_dump(isset($a->asd));echo "</pre>";
echo "<pre>";var_dump(empty($a->foo));echo "</pre>";
echo "<pre>";var_dump(empty($a->asd));echo "</pre>";
echo "<pre>";var_dump(@$a->foo);echo "</pre>";


Expected result:
----------------
Fatal error:  Cannot use array as object in ...

OR

bool(false)

bool(false)

bool(true)

bool(true)

NULL


Actual result:
--------------
bool(true)

bool(false)

bool(false)

bool(true)

NULL


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2009-11-21 21:13 UTC] tyra3l at gmail dot com
could you show me which ticket duplicates this, and where this behavior is documented in the manual?
because I tried to check this in the documentation, but I haven't found it at the isset/empty manual page.

Tyrael
 [2009-11-23 13:28 UTC] jani@php.net
I'm sorry, I read this a bit hastily. This indeed is a bug.
 [2009-11-23 14:07 UTC] tyra3l at gmail dot com
Thank you for verifying this.
It was noticed on our development machines, and I tested it on different 
php installations, so I can confirm this is also present on 
5.2.5,5.2.8,5.2.11 also.

Tyrael
 [2009-11-24 21:54 UTC] felipe@php.net
This bug has been fixed in SVN.

Snapshots of the sources are packaged every three hours; this change
will be in the next snapshot. You can grab the snapshot at
http://snaps.php.net/.
 
Thank you for the report, and for helping us make PHP better.


 [2009-11-24 21:54 UTC] svn@php.net
Automatic comment from SVN on behalf of felipe
Revision: http://svn.php.net/viewvc/?view=revision&revision=291282
Log: - Fixed bug #50255 (isset() and empty() silently casts array to object)
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 17 21:01:56 2014 UTC