Cms: Stopped working with Symfony 5.1.0

Created on 31 May 2020  路  9Comments  路  Source: statamic/cms

Bug Description

Updating composer package today loaded the latest Symfony release v5.1.0 and Statamic stop working with this version.

How to Reproduce

run composer update

Extra Detail

the error :

TypeError
Argument 2 passed to str_contains() must be of the type string, array given, called in [...]/vendor/statamic/cms/src/View/Antlers/Parser.php on line 1182

the error stack trace :

Screenshot 2020-05-31 at 10 24 08

Environment

Statamic version: 3.0.0-beta.28

PHP version: 7.4.6

Install method: Fresh install from statamic/statamic

Most helpful comment

All 9 comments

I'm seeing this too after a composer update this morning

The Statamic Parser.php does

str_contains($key, [':', '.'])

Which as far as I can see was never allowed in the PHP8 RFC for str_contains

(Symfony is just polyfilling PHP8 by the looks of things)

I fixed this by changing that line to:

      if (! (str_contains($key, ':') || str_contains($key, '.'))) {

But there may be a more efficient way.

I think they should use Str::contains($haystack, $needles) instead.

@rosswintle / @jimblue can you confirm my suggestion works?

Just tried:

if (!(Str::contains($key, ':')) || Str::contains($key, '.')) {
          return [false, null];
}

and

if (!(str_contains($key, ':') || str_contains($key, '.'))) {
         return [false, null];
}

and both are working 馃憤

Looks like that new helper from Symfony gets loaded before Laravels. Neat.

Decent example why global functions aren鈥檛 a great idea.

For now, on Forge at least, a quick

sed -i 's/str_contains/Str::contains/g' vendor/statamic/cms/src/View/Antlers/Parser.php

right after composer install will patch this up.

Tks @jasonvarga ! 馃帀

To be fair, Laravel deprecated str_ and arr_ global functions a while ago, in favour of their Str and Arr classes respectively. Good change 馃憤

Was this page helpful?
0 / 5 - 0 ratings

Related issues

sauerbraten picture sauerbraten  路  3Comments

ReneWeCode picture ReneWeCode  路  3Comments

robdekort picture robdekort  路  3Comments

aerni picture aerni  路  3Comments

mattrothenberg picture mattrothenberg  路  3Comments