php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #80836 is_array defies it own purpose by throwing fatal when passed an stdClass
Submitted: 2021-03-05 21:14 UTC Modified: 2021-03-05 23:21 UTC
From: chris at summit-tech dot ca Assigned:
Status: Not a bug Package: Compile Failure
PHP Version: 8.0.3 OS: Windows
Private report: No CVE-ID: None
 [2021-03-05 21:14 UTC] chris at summit-tech dot ca
Description:
------------
This function has been rendered utterly useless as passing it some non-array objects such as stdClass results in a ridiculous error: Fatal error: Uncaught Error: Cannot use object of type stdClass as array

Test script:
---------------
$test->bla = "bla"; //Forcibly makes an stdClass obj
if (is_array($test)){
 echo "This doesn't run";
}

Expected result:
----------------
is_array should return false and not stupidly throw a fatal

Actual result:
--------------
fatal error that defies the purpose of this function's entire existence

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2021-03-05 21:20 UTC] chris at summit-tech dot ca
-Status: Open +Status: Closed
 [2021-03-05 21:20 UTC] chris at summit-tech dot ca
Incorrectly described, closing
 [2021-03-05 21:21 UTC] daverandom@php.net
-Status: Closed +Status: Open
 [2021-03-05 21:21 UTC] daverandom@php.net
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit http://www.php.net/support.php as this bug system is not the
appropriate forum for asking support questions.  Due to the volume
of reports we can not explain in detail here why your report is not
a bug.  The support channels will be able to provide an explanation
for you.

Thank you for your interest in PHP.

The error produced by this code is due to treating an undefined variable as an object, nothing to do with is_array() https://3v4l.org/hOQov

Although it is possible to implicitly declare an array in this fashion, the same is not true of an object, which is a reference value and thus cannot be used unless it has been explicitly created.
 [2021-03-05 21:21 UTC] daverandom@php.net
-Status: Open +Status: Not a bug
 [2021-03-05 21:21 UTC] daverandom@php.net
Not sure why my comment re-opened, re-closing
 [2021-03-05 23:21 UTC] chris at summit-tech dot ca
Yep my apologies and i think the ticket reopened because we submitted our comment at the same moment :)
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 21:01:27 2024 UTC