3v4l.org

run code in 150+ php & hhvm versions
Bugs & Features
<?php function object_diff($source, $target) { if (!is_object($source) || !is_object($target) || !($source instanceof $target)) { return null; } $sourceProperties = []; $targetProperties = []; $sourceReflection = new ReflectionObject($source); $targetReflection = new ReflectionObject($target); foreach ($sourceReflection->getProperties() as $sourceProperty) { $sourceProperty->setAccessible(true); $sourceProperties[$sourceProperty->getName()] = $sourceProperty->getValue($source); } foreach ($targetReflection->getProperties() as $targetProperty) { $targetProperty->setAccessible(true); $targetProperties[$targetProperty->getName()] = $targetProperty->getValue($target); } return array_diff($sourceProperties, $targetProperties); } class Foo { private $a, $b, $c; public function __construct($a, $b, $c) { $this->a = $a; $this->b = $b; $this->c = $c; } } $foo1 = new Foo('1', '2', '3'); $foo2 = new Foo('1', '3', '4'); var_dump(object_diff($foo1, $foo2));
Output for 5.4.0 - 7.1.0
array(1) { ["b"]=> string(1) "2" }
Output for 5.1.0 - 5.3.29
Parse error: syntax error, unexpected '[' in /in/ArEJc on line 9
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected '[' in /in/ArEJc on line 9
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING in /in/ArEJc on line 5
Process exited with code 255.
Output for 4.3.0 - 4.3.1, 4.3.5 - 4.4.1
Parse error: parse error, unexpected T_STRING in /in/ArEJc on line 5
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error in /in/ArEJc on line 5
Process exited with code 255.