Solve the problem of upgrading to php 7.2 in laravel 5.4 application

I updated my version of laravel php to php 7.2 this week, and since then I have run into big problems in my laravel application . before upgrading php to 7.2, every thing worked efficiently.

The main problem is the count () and array_merge () functions that cause this error:

for a function, the array_merge()code is as follows:

$array = array_merge(
                $model->toSearchableArray(), $model->scoutMetadata()
            );

            if (empty($array)) {
                return;
            }

ErrorException · array_merge (): Argument # 1 is not an array.

and I encountered an error count(), for example, in this code, when the model does not return records and returns null:

count(TutorialReview::where('TutorialID', 5)->where('UserID', 6)->get())

count(): , .

laravel 5.4

, laravel 5.5 ?

+4
5

PHP 7.2 count() RFC: https://wiki.php.net/rfc/counting_non_countables

, ->count() laravel, :

$count = TutorialReview::where('TutorialID', 5)->where('UserID', 6)->get()->count();

, .

+1

:

$array = array_merge(
    collect($model->toSearchableArray())->toArray(), $model->scoutMetadata()
);

->count() count()

0

array_merge(), :

  • sluggable.php app/config

    return ['source' = > null, 'maxLength' = > null, 'method' = > null, 'separator' = > '-', 'unique' = > true, 'uniqueSuffix' = > null, ' includeTrashed '= > false,' reserved '= > null,' onUpdate '= > false,];

  • php artisan config:cache

count():

count(): Parameter must be an array or an object that implements Countable.

, , . Laravel 5.4 5.5 Php 7.2. Count() PHP 7.2

PHP 7.1 , .

0

in PHP 7.2 The method of counting is unavailable due to security reasons, you need to install an extension to view this documentation

https://wiki.php.net/rfc/counting_non_countables

0
source

Just add @ before counting. @count (object or array);

0
source

Source: https://habr.com/ru/post/1690834/


All Articles