php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #79803 array_key_exists not returning bool
Submitted: 2020-07-07 09:52 UTC Modified: 2020-07-07 10:13 UTC
From: marekvikartovsky at gmail dot com Assigned: cmb (profile)
Status: Not a bug Package: Arrays related
PHP Version: Irrelevant OS:
Private report: No CVE-ID: None
 [2020-07-07 09:52 UTC] marekvikartovsky at gmail dot com
Description:
------------
---
From manual page: https://php.net/function.array-key-exists
---

Hello,

if I am calling array_key_exists on NULL by mistake, the function should return bool FALSE, not NULL. I understand that it shows me a warning, but it also should return bool value as in documentation.

I tested it on PHP version 7.1.33 and 7.4.7

Test script:
---------------
var_dump(array_key_exists('test', NULL));

Expected result:
----------------
By documentation I am expecting to return a bool value, not NULL or you should return an exception, not warning.


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2020-07-07 10:06 UTC] cmb@php.net
-Status: Open +Status: Not a bug -Assigned To: +Assigned To: cmb
 [2020-07-07 10:06 UTC] cmb@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

<https://www.php.net/manual/en/functions.internal.php>
 [2020-07-07 10:13 UTC] marekvikartovsky at gmail dot com
Thanks for your time, I didnt seen, that there is wrote "This behaviour should not be relied upon, and care should be taken to ensure that array is an array."

Thank you,

Have a nice day!
 [2020-07-07 10:13 UTC] kocsismate@php.net
Moreover, the behaviour has been changed for PHP 8 so that an exception is thrown if the second argument is not an array.
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Tue Sep 29 12:01:24 2020 UTC