|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2006-12-07 10:41 UTC] techtonik@php.net
[2006-12-07 10:50 UTC] tony2001@php.net
[2006-12-07 12:27 UTC] techtonik@php.net
[2006-12-07 12:35 UTC] tony2001@php.net
[2006-12-07 12:56 UTC] techtonik@php.net
[2006-12-07 13:11 UTC] tony2001@php.net
[2006-12-07 13:33 UTC] techtonik@php.net
[2008-11-27 02:10 UTC] jani@php.net
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sun Oct 26 22:00:01 2025 UTC |
Description: ------------ Array indexes can be resources - in this case they are casted to int automatically without any warning (E_STRICT is turned off in PHP5). Hovewer, array_key_exists() throws warning if resource is passed as a key and fails to recognize the key. This leads to confusion and is illustrated below. More logical behavior is to make conversion automatically and display warning only in E_STRICT mode for PHP5. Yes, the problem persists in PHP5 as well. Reproduce code: --------------- <?php $depth = array(); $parser = xml_parser_create(); $depth[$parser] = "xxx"; echo "\n -".array_key_exists((int)$parser, $depth); echo "\n -".array_key_exists("" + $parser, $depth); echo "\n -".array_key_exists("" . $parser, $depth); echo "\n -".array_key_exists((int) $parser, $depth); echo "\n".$depth[$parser]; echo "\n".$depth[(int)$parser]; echo "\n"; $z = "" + $parser; var_dump($z); $z = "" . $parser; var_dump($z); $z = (string) $parser; var_dump($z); $z = strval($parser); var_dump($z); exit(); Expected result: ---------------- Warning: array_key_exists(): The first argument should be either a string or an integer in C:\php51\test00.php on line 8 - -1 - -1 xxx int(4) string(14) "Resource id #4" string(14) "Resource id #4" string(14) "Resource id #4" Actual result: -------------- -1 -1 - -1 xxx int(4) string(14) "Resource id #4" string(14) "Resource id #4" string(14) "Resource id #4"