What potential pitfalls should be considered when using array_push() to append objects to an array in PHP?

When using array_push() to append objects to an array in PHP, it's important to note that array_push() will add the object as a whole, not its individual properties. This means that changes made to the object after pushing it into the array will reflect in all occurrences within the array. To avoid this, you can create a copy of the object before pushing it into the array.

// Create a copy of the object before pushing it into the array
$objectCopy = clone $object;
array_push($array, $objectCopy);