Bug #77286 [Com]: The array key like '123' Not a string?

From: Date: Wed, 12 Dec 2018 10:48:17 +0000
Subject: Bug #77286 [Com]: The array key like '123' Not a string?
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218416@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=77286&edit=1 ID: 77286 Comment by: spam2 at rhsoft dot net Reported by: xpigeon at 163 dot com Summary: The array key like '123' Not a string? Status: Not a bug Type: Bug Package: *General Issues Operating System: Windows 7 PHP Version: 7.3.0 Block user comment: N Private report: N New Comment: FWIW with strict-types that code has been a type error for years <?php declare(strict_types=1); $value = 'mystr-abcd-1234'; $keys = ['123'=>0, '456'=>0, '789'=>0, 'abc'=>0, 'xyz'=>0]; foreach($keys as $key=>$value) { if(strstr($value,$key)) { $keys[$key]=1; } } ?> Fatal error: Uncaught TypeError: strstr() expects parameter 1 to be string, integer given in /mnt/data/downloads/test.php:6 Stack trace: #0 /mnt/data/downloads/test.php(6): strstr(0, 123) #1 {main} thrown in /mnt/data/downloads/test.php on line 6 Previous Comments: ------------------------------------------------------------------------ [2018-12-12 05:55:43] xpigeon at 163 dot com to: a at b dot c dot de Yeah! I just want find this! But indeed, I read this document, But I was NOT read it carefully! ------------------------------------------------------------------------ [2018-12-12 05:41:10] a at b dot c dot de It's not a bug if it's a deliberate and documented change. http://www.php.net/manual/zh/migration73.deprecated.php#migration73.deprecated.core.string-search ------------------------------------------------------------------------ [2018-12-12 04:43:45] xpigeon at 163 dot com Thanks! I have this code in a project, it runs ok in php7.2; But in php7.3, it show Notice Error, So I report is as a bug! 您从我的邮箱及蹩脚的英文中猜出我是来中国!? 再次感谢! ------------------------------------------------------------------------ [2018-12-12 04:15:09] requinix@php.net http://php.net/manual/zh/language.types.array.php > > 包含有合法整型值的字符串会被转换为整型。例如键名 > "8" 实际会被储存为 8。但是 "08" > 则不会强制转换,因为其不是一个合法的十进制数值。 var_dump($key) -> int(123), int(456), int(789), string(3) "abc", string(3) "xyz" ------------------------------------------------------------------------ [2018-12-12 04:10:17] xpigeon at 163 dot com This line will Annotated: ``` if(strstr($value,"$key")){ // is OK ``` -=> Edit as ``` //if(strstr($value,"$key")){ // is OK ``` ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=77286 -- Edit this bug report at https://bugs.php.net/bug.php?id=77286&edit=1

« previous php.bugs (#218416) next »