错误消息:已弃用的功能:strpos():将 null 传递给参数 #1 ($haystack)

问题描述 投票:0回答:1

自从 PHP 从 7.4 升级到 8.1 以来,我们在应用程序中收到此错误:

Error message: Deprecated Functionality: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /Model/Plugin/Order.php on line 33

第 33 行是 IF 语句

33. if (strpos($orderStatus, '_') !== false) {
34. do stuff...
35. }

是否可以以某种方式更改它以能够处理空值?

谢谢,

php strpos
1个回答
0
投票

您也可以这样做,因为如果 $orderStatus 为 null,则 strpos 将不会执行:

if( $orderStatus == null || strpos($orderStatus, '_') { 做东西 }

最新问题
© www.soinside.com 2019 - 2025. All rights reserved.