Doc #80978 [NEW]: array_key_exists() does not work for false/true

From: Date: Fri, 23 Apr 2021 16:48:05 +0000
Subject: Doc #80978 [NEW]: array_key_exists() does not work for false/true
Groups: php.doc.bugs 
Request: Send a blank email to doc-bugs+get-18722@lists.php.net to get a copy of this message
From: reed dot hi at taeluf dot com Operating system: Fedora 33 PHP version: 7.4.16 Package: Reproducible crash Bug Type: Documentation Problem Bug description:array_key_exists() does not work for false/true Description: ------------ --- From manual page: https://php.net/function.array-key-exists --- array_key_exists() returns false when checking for a key that is boolean false or true, yet the value can be accessed by $thearray[false] & array_keys($thearray) includes the boolean true/false null is not int|string, but works without issue, so I think that part is a documentation issue. Test script: --------------- $data = [false=>'happy', null=>'sad', true=>'also happy']; var_dump(array_key_exists(true, $data)); // false, PHP Warning var_dump(array_key_exists(false, $data)); // false, PHP Warning var_dump(array_key_exists(null, $data)); // true, No Warning var_dump($data[false]); // happy var_dump( in_array(false,array_keys($data)) ); // true var_dump( in_array(true,array_keys($data)) ); // true var_dump( in_array(null,array_keys($data)) ); // true Expected result: ---------------- var_dump output: true true true "happy" true true true (and no errors) Actual result: -------------- var_dump output: false false true "happy" true true true PHP Warning: array_key_exists(): The first argument should be either a string or an integer PHP Warning: (same warning again) -- Edit bug report at https://bugs.php.net/bug.php?id=80978&edit=1 -- Fix committed: https://bugs.php.net/fix.php?id=80978&r=fixed Fixed in release: https://bugs.php.net/fix.php?id=80978&r=alreadyfixed Need backtrace: https://bugs.php.net/fix.php?id=80978&r=needtrace Need Reproduce Script: https://bugs.php.net/fix.php?id=80978&r=needscript Try newer version: https://bugs.php.net/fix.php?id=80978&r=oldversion Not developer issue: https://bugs.php.net/fix.php?id=80978&r=support Expected behavior: https://bugs.php.net/fix.php?id=80978&r=notwrong Not enough info: https://bugs.php.net/fix.php?id=80978&r=notenoughinfo Submitted twice: https://bugs.php.net/fix.php?id=80978&r=submittedtwice register_globals: https://bugs.php.net/fix.php?id=80978&r=globals PHP version support discontinued: https://bugs.php.net/fix.php?id=80978&r=phptooold Daylight Savings: https://bugs.php.net/fix.php?id=80978&r=dst IIS Stability: https://bugs.php.net/fix.php?id=80978&r=isapi Install GNU Sed: https://bugs.php.net/fix.php?id=80978&r=gnused Floating point limitations: https://bugs.php.net/fix.php?id=80978&r=float No Zend Extensions: https://bugs.php.net/fix.php?id=80978&r=nozend MySQL Configuration Error: https://bugs.php.net/fix.php?id=80978&r=mysqlcfg

« previous php.doc.bugs (#18722) next »