Skip to content

PHP 8.4 deprecated implicitly nullable parameters and registerMacros() method fails. #352

@eneadm

Description

@eneadm

PHP 8.4 has deprecated implicitly nullable parameters. In previous versions, writing array $transformers = null was valid, but now PHP requires an explicit nullable type declaration using ?.

Error:

PHP Deprecated:  {closure:Algolia\ScoutExtended\ScoutExtendedServiceProvider::registerMacros():128}(): Implicitly marking parameter $transformers as nullable is deprecated, the explicit nullable type must be used instead in /var/www/html/vendor/algolia/scout-extended/src/ScoutExtendedServiceProvider.php on line 128

Fix:

Algolia\ScoutExtended\ScoutExtendedServiceProvider:L126

\Illuminate\Database\Eloquent\Builder::macro('transform', function (array $array, ?array $transformers = null) {
    foreach ($transformers ?? UpdateJob::getTransformers() as $transformer) {
        $array = app($transformer)->transform($this->getModel(), $array);
    }

    return $array;
});

This should fix the issue and makes the package fully compatible with the latest php version. Let me know if I should make a PR for this change :-)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions