Req #80162 [NEW]: array_key_exists() should support ArrayAccess
| From: | divinity76 at gmail dot com | Date: | Tue, 29 Sep 2020 23:11:42 +0000 |
| Subject: | Req #80162 [NEW]: array_key_exists() should support ArrayAccess | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-229278@lists.php.net to get a copy of this message | ||
From: divinity76 at gmail dot com
Operating system:
PHP version: Next Minor Version
Package: Unknown/Other Function
Bug Type: Feature/Change Request
Bug description:array_key_exists() should support ArrayAccess
Description:
------------
i suggest changing
array_key_exists ( mixed $key , array $array ) to
array_key_exists ( mixed $key , array|ArrayAccess $array ) , it's
awkward that array_key_exists can't check ArrayAccess objects
(and it has caused invalid bugreports in the past, ref
https://bugs.php.net/bug.php?id=46354 and
https://bugs.php.net/bug.php?id=34849 )
Test script:
---------------
<?php
class C implements ArrayAccess {
public $data = array(
"foo"=>"bar"
);
public function offsetExists ( $offset ): bool{
return array_key_exists($offset,$this->data);
}
public function offsetGet ( $offset ){
return $this->data[$offset];
}
public function offsetSet ( $offset , $value ): void {
$this->data[$offset]=$value;
}
public function offsetUnset ( $offset ): void {
unset($this->data[$offset]);
}
}
$o=new C();
var_dump(array_key_exists('foo',$o));
Expected result:
----------------
bool(true)
Actual result:
--------------
Fatal error: Uncaught TypeError: array_key_exists(): Argument #2
($array) must be of type array, C given in /in/ZrcrF:24
Stack trace:
#0 {main}
thrown in /in/ZrcrF on line 24
Process exited with code 255.
--
Edit bug report at https://bugs.php.net/bug.php?id=80162&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=80162&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=80162&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=80162&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=80162&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=80162&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=80162&r=support
Expected behavior: https://bugs.php.net/fix.php?id=80162&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=80162&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=80162&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=80162&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=80162&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=80162&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=80162&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=80162&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=80162&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=80162&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=80162&r=mysqlcfg