isset() and empty() silently casts array to object
| 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 (profile) | ||
| Status: | Closed | Package: | Scripting Engine problem | ||
| PHP Version: | 5.*, 6 | OS: | * | ||
| Private report: | No | CVE-ID: | None | ||
[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
Pull Requests
History
AllCommentsChangesGit/SVN commits
[2009-11-21 21:13 UTC] tyra3l at gmail dot com
[2009-11-23 13:28 UTC] jani@php.net
[2009-11-23 14:07 UTC] tyra3l at gmail dot com
[2009-11-24 21:54 UTC] felipe@php.net