note 123591 added to arrayaccess.offsetexists

From: Date: Fri, 08 Feb 2019 11:41:49 +0000
Subject: note 123591 added to arrayaccess.offsetexists
Groups: php.notes 
Request: Send a blank email to php-notes+get-210200@lists.php.net to get a copy of this message
If you care about key-strictness, you may need to use an alternative solution (maybe overriding offsetExists() in subclass(es)). So, offsetExists() acts like array_key_exists() and does not handle the key types. Here; <?php $array = ['one', 'two', 3.=>'boom!']; $arrayObject = new ArrayObject($array); $key = '3'; var_dump(array_key_exists($key, $array)); // bool(true) var_dump(in_array($key, array_keys($array), true)); // bool(false) var_dump($arrayObject->offsetExists($key)); // bool(true) var_dump(in_array($key, array_keys($arrayObject->getArrayCopy()), true)); // bool(false) // @override; public function offsetExists($key) { // make a strict check return in_array($key, array_keys($this->getArrayCopy()), true); } ?> ---- Server IP: 208.43.231.9 Probable Submitter: 185.85.3.142 (proxied: 2001:67c:2660:425:4::802) ---- Manual Page -- http://php.net/manual/en/arrayaccess.offsetexists.php Edit -- https://master.php.net/note/edit/123591 Del: integrated -- https://master.php.net/note/delete/123591/integrated Del: useless -- https://master.php.net/note/delete/123591/useless Del: bad code -- https://master.php.net/note/delete/123591/bad+code Del: spam -- https://master.php.net/note/delete/123591/spam Del: non-english -- https://master.php.net/note/delete/123591/non-english Del: in docs -- https://master.php.net/note/delete/123591/in+docs Del: other reasons-- https://master.php.net/note/delete/123591 Reject -- https://master.php.net/note/reject/123591 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#210200) next »