I thing the issue arises because $result can be a string or null after preg_replace, and then it gets reassigned to an array after explode.
To resolve this, you can explicitly type-check the result after preg_replace and ensure the type remains consistent. Here's a modified version of your code:
<?php
declare(strict_types=1);
namespace Devsense\Builtin;
$result = preg_replace('/test/i', 'TEST', 'test');
if ($result !== null && $result !== '') {
// This ensures $result is a string
$result = ucfirst($result);
} else {
$result = ''; // Optional: Define a default value if needed
}
/**
* Ensure $result is explicitly treated as an array
*/
$result = explode(',', '1,2,3');
This way, you clarify the expected types and avoid the PHP0406 error.
Thanks