eloquent-preferences icon indicating copy to clipboard operation
eloquent-preferences copied to clipboard

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

Open TheFrankman opened this issue 2 years ago • 5 comments

This error for me fires many times when running PHPunit. Not sure what the exact scenario is for recreating it as we run hundreds of tests.

Deprecated: strpos(): Passing null to parameter #1 ($haystack) of type string is deprecated in /../vendor/klaude/eloquent-preferences/src/HasPreferences.php on line 306

We are running laravel v9 with PHP 8.1

TheFrankman avatar Mar 29 '22 14:03 TheFrankman

Howdy, @TheFrankman. Thanks for the issue and for using the library. I haven't done much testing in PHP 8+ and Laravel 9 yet, but it looks high time to start. I'll look into this in the coming days.

klaude avatar Mar 29 '22 16:03 klaude

@klaude - thanks for the swift response. I did look into create a PR for this, but it's a bit more complicated that I first thought. Please let me know if there is anything else I can do to help!

TheFrankman avatar Mar 30 '22 15:03 TheFrankman

Oh, and this is also an issue on Laravel 8.x

TheFrankman avatar Mar 30 '22 15:03 TheFrankman

That helps a lot, thanks! It may be time cut out a bunch of old Laravel and PHP compatibility work then release versions 1.0.0 and 2.0.0 with older code support and newer code support.

klaude avatar Mar 30 '22 16:03 klaude

@klaude I think this can just be resolved like so :

Old code :

if (method_exists($this, 'asDecimal') && strpos($castTo, 'decimal:') === 0) {
    return $this->asDecimal($value, explode(':', $castTo, 2)[1]);
}

New code :

 if (method_exists($this, 'asDecimal') && $castTo && strpos($castTo, 'decimal:') === 0) {
    return $this->asDecimal($value, explode(':', $castTo, 2)[1]);
}

I'm going to create a fork for now because this issue is blocking our unit tests and therefore, deployments.

TheFrankman avatar Mar 31 '22 08:03 TheFrankman