|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2018-12-12 04:07 UTC] 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
*/
?>
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Nov 01 07:00:01 2025 UTC |
This line will Annotated: ``` if(strstr($value,"$key")){ // is OK ``` -=> Edit as ``` //if(strstr($value,"$key")){ // is OK ```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