- array_diff: documentation ( source)
- set_error_handler: documentation ( source)
<?php
set_error_handler(function (int $severity, string $message, string $filename, int $line) {
echo "throwing\n";
throw new ErrorException($message, 0, $severity, $filename, $line);
});
$stdObject = new stdClass(); //Can't be casted to string
//array_diff compares array items CASTING them to string
//http://php.net/manual/en/function.array-diff.php
try {
array_diff([], [$stdObject]);
}catch(ErrorException $ee){
echo "Catched exception: " . $ee->getMessage() . "\n";
}
echo "\n----------\n";
try {
array_diff([$stdObject], []);
}catch(ErrorException $ee){
echo "Catched exception: " . $ee->getMessage() . "\n";
}