Are there any potential pitfalls when using in_array function in PHP to check for objects?

When using the in_array function in PHP to check for objects, it's important to note that by default, in_array uses loose comparison (==) which may not work as expected when comparing objects. To solve this issue, you can use the strict comparison (===) by setting the third parameter of in_array to true.

// Example code snippet to check for objects using strict comparison
$object1 = new stdClass();
$object2 = new stdClass();
$objects = [$object1, $object2];

if (in_array($object1, $objects, true)) {
    echo "Object1 found in the array";
} else {
    echo "Object1 not found in the array";
}