Bug #77286 [Opn->Nab]: The array key like '123' Not a string?

From: Date: Wed, 12 Dec 2018 04:15:09 +0000
Subject: Bug #77286 [Opn->Nab]: The array key like '123' Not a string?
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-218404@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 Updated by: requinix@php.net Reported by: xpigeon at 163 dot com Summary: The array key like '123' Not a string? -Status: Open +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: 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" Previous Comments: ------------------------------------------------------------------------ [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 ``` ------------------------------------------------------------------------ [2018-12-12 04:07:16] xpigeon at 163 dot com Description: ------------ In the array like this: ``` '123'=>'abc' ``` The key like '123' Not as a string? Test script: --------------- <?php $value = 'mystr-abcd-1234'; $keys = ['123'=>0, '456'=>0, '789'=>0, 'abc'=>0, 'xyz'=>0]; foreach($keys as $key=>$v){ if(strstr($value,"$key")){ // is OK if(strstr($value,$key)){ // Notice Error $keys[$key]=1; } } var_dump($keys); die(); /* php7.3 strstr(): Non-string needles will be interpreted as strings in the future. Use an explicit chr() call to preserve the current behavior */ ?> ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=77286&edit=1

« previous php.bugs (#218404) next »