|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #77286 The array key like '123' Not a string?
Submitted: 2018-12-12 04:07 UTC Modified: 2018-12-12 04:15 UTC
From: xpigeon at 163 dot com Assigned:
Status: Not a bug Package: *General Issues
PHP Version: 7.3.0 OS: Windows 7
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
Block user comment
Status: Assign to:
Bug Type:
From: xpigeon at 163 dot com
New email:
PHP Version: OS:


 [2018-12-12 04:07 UTC] xpigeon at 163 dot com
In the array like this:
The key like '123' Not as a string?

Test script:
$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
strstr(): Non-string needles will be interpreted as strings in the future. 
Use an explicit chr() call to preserve the current behavior


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2018-12-12 04:10 UTC] 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:15 UTC]
-Status: Open +Status: Not a bug
 [2018-12-12 04:15 UTC]
> 包含有合法整型值的字符串会被转换为整型。例如键名 "8" 实际会被储存为 8。但是 "08" 则不会强制转换,因为其不是一个合法的十进制数值。

var_dump($key) -> int(123), int(456), int(789), string(3) "abc", string(3) "xyz"
 [2018-12-12 04:43 UTC] xpigeon at 163 dot com
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 05:41 UTC] a at b dot c dot de
It's not a bug if it's a deliberate and documented change.
 [2018-12-12 05:55 UTC] 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 10:48 UTC] spam2 at rhsoft dot net
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)

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
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Sat May 08 11:01:23 2021 UTC