Closed dniccum closed 2 years ago
I just ran into this as well. Everything works fine when fixing the Laravel version to "laravel/framework": "8.80"
but fails with "laravel/framework": "^8.0"
. It seems to be an issue with Laravel 8.81
.
Hi @jasonvarga
I ran into the same problem before I found this issue only after I had already looked in the code.
At first, it seemed to be a problem with the parameter order of Statamic\Support\Str where the signature is
replace($string, $search, $replace)
(in latest version v3.2.31 https://github.com/statamic/cms/blob/v3.2.31/src/Support/Str.php#L262) but Laravel's Str::replace uses
replace($search, $replace, $subject)
(did not change in the last 9 months https://github.com/laravel/framework/blame/8.x/src/Illuminate/Support/Str.php#L612).
When I did change the arguments of Statamic\Support\Str's replace method to the compatible signature public static function replace($search, $replace, $string)
(https://github.com/statamic/cms/blob/v3.2.31/src/Support/Str.php#L262) it then goes on.
But then it calls Stringy's replace method (https://github.com/statamic/Stringy/blob/master/src/Stringy.php#L1077).
public function replace($search, $replacement)
{
return $this->regexReplace(preg_quote($search), $replacement);
}
I think here lays the main problem, that preg_quote
is just not compatible with $search be an array (what is supported by the default Laravel replace method as it just uses the built-in str_replace
method and the studly method in Laravel 8.80 did).
As this is fixed now, I thought my deep dive helps identify the core problem about this "bug".
Here is the PR changing the studly method for Laravel v8.81.0 https://github.com/laravel/framework/commit/3d50d374ab9f473ef2d2daf5008f146a60e7ce07#diff-262e10b3591ac74c9157a3e732ee544209ea224da8af4844ebacbb1e8e2713d4L842
And here is the Blame for the method: https://github.com/laravel/framework/blame/8.x/src/Illuminate/Support/Str.php#L840
Maybe the old Stringy replace method could be made compatible to allow multiple search needles to prevent copy pasting code from the source of Laravel?
I just saw that you anyway want to remove the Stringy dependency, which will solve this problem too 👍
Our Str::replace()
had always used Stringy's version, which broke when Laravel added their own Str::replace()
. So yes, we'll be addressing that in 4.0. Not really something we can change at the moment.
Bug description
After performing a version update, I am receiving an error with the
statamic/stringy/src/Stringy.php
utility that is included with the Statamic CMS. This does appear to be a breaking issue as any of thephp artisan
andphp please
commands throw the error.How to reproduce
composer.json
file:"laravel/framework": "^8.81"
composer dumpautoload
command to leverage Laravel's auto package discoveryLogs
Versions
Installation
Starter Kit using via CLI
Additional details
No response