Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

iamssingh's avatar

array_key_exists(): Using array_key_exists() on objects is deprecated in Laravel 6 with PHP 7.4

array_key_exists(): Using array_key_exists() on objects is deprecated. Use isset() or property_exists() instead headerTwo.blade.php in Laravel 7.4

I am working with an Laravel project, that is using Laravel 6. I am using PHP 7.4 and it showed me error above. How can i set it up with Php 7.4

0 likes
3 replies
ahmeddabak's avatar

The error is clear. in this file headerTwo.blade.php you are using array_key_exists() to check if an object has a specific property. which is now deprecated. so you instead use isset like this isset($object->property) of using property_exists like this property_exists($object,'property')

djallits's avatar

PHP is deprecating array_key_exists. It will be completely removed from PHP in version 8. Right now it is just a deprecation warning and your application will continue to work as long as you do not update PHP to version 8 when it is released. However, it would be prudent to resolve this issue now in your code as described by @ahmeddabak, as you may not remember that this will be needed to be done when 8 arrives which will be in Q4 2020 or Q1 2021.

The documentation already marks the use of array_key_exists() with objects as legacy behavior:

array_key_exists() on objects also has some technical issues: It operates directly on mangled property names and does not respect property visibility. Furthermore, it does not take into account differences in normalization between array and object keys, so incorrect results may be returned for properties with integral keys.

Additionally, the fact that array_key_exists() accepts objects may mistakenly lead users to believe that it can operate on ArrayAccess objects in a sensible manner. This is not the case: array_key_exists() has no support for ArrayAccess, it exclusively works on mangled object properties.

Please or to participate in this conversation.