Aknot
Aknot

Reputation: 519

Error message: Deprecated Functionality: strpos(): Passing null to parameter #1 ($haystack)

Since a upgrade to PHP 8.1 from 7.4 we are getting this error in an application:

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

Line 33 is a IF-statement

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

Is it possible to change it in someway to be able to handle null values?

Thanks,

Upvotes: 2

Views: 2273

Answers (1)

sdduuuude
sdduuuude

Reputation: 21

You can also do this because the strpos will not execute if the $orderStatus is null:

if( $orderStatus == null || strpos($orderStatus, '_') { do stuff }

Upvotes: 2

Related Questions