Home » Php » php – array_key_exists() error / edit a vendor file

php – array_key_exists() error / edit a vendor file

Posted by: admin February 25, 2020 Leave a comment

Questions:

I have a small problem in my laravel API deployed in heroku, that started to happen to me from nowhere, without updating anything or making any relevant changes, and it happens to me when I try to use any eloquent resource, for example when doing:

$brands = Brand::paginate(15);
return BrandResource::collection($brands);

I get this error:

array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead

in DelegatesToResource.php line 49

Investigating a bit, get to the file: DelegatesToResource.php in vendor, and in effect it use:

 public function offsetExists($offset)
{
    return array_key_exists($offset, $this->resource);
}

To make a test, I created a new Laravel project, and in fact it comes with that line already corrected, like this:

public function offsetExists($offset)
{
    return isset($this->resource[$offset]);
}

If there is any way to solve this in my project, I understand that I should not and cannot change files in vendor, so my question is what to do in this case?

I´m using Laravel Framework 5.6.39 and PHP 7.2.18 (cli)

How to&Answers: