FATAL - E_ERROR -> BlockPatterns.php #57761
Closed
alexandrego
started this conversation in
WooCommerce, Blocks, and Site Editing
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
I don't know if this is exactly where we report errors, but here's what I identified in our ecommerce this morning (05/06/2025 - 10am).
Error message: Uncaught TypeError: strpos(): Argument #1 ($haystack) must be of type string, null given in ....
function ( $category ) {
foreach ( self::CATEGORIES_PREFIXES as $prefix ) {
if ( strpos( $category['title'], $prefix ) !== false ) {
$parsed_category = str_replace( $prefix, '', $category['title'] );
$parsed_category = str_replace( '_', ' ', $parsed_category ); $category['title'] = ucfirst( $parsed_category );
}
}
return $category;
},
The error occurs because the strpos() function is receiving a null value instead of a string, which is not allowed in newer versions of PHP.
If $category['title'] is null, the error will be thrown. To fix this, I added a check to make sure $category['title'] is actually a string before calling strpos():
if ( isset($category['title']) && is_string($category['title']) ) {
foreach ( self::CATEGORIES_PREFIXES as $prefix ) {
if ( strpos( $category['title'], $prefix ) !== false ) {
$parsed_category = str_replace( $prefix, '', $category['title'] );
$parsed_category = str_replace( '_', ' ', $parsed_category );
$category['title'] = ucfirst( $parsed_category );
}
}
}
Beta Was this translation helpful? Give feedback.
All reactions