run code in 200+ php & hhvm versions
Bugs & Features
<?php $desc = '{"a":1, "b":2}'; $ob = '{"a":1, "b":2, "c":3}'; function isLikeThis(string $description, string $tested) { $args = array_map(function($arg){ get_object_vars(json_decode($arg)); }, func_get_args() ); return !(bool)call_user_func_array('array_diff_assoc', $args); } var_dump(isLikeThis($desc, $ob));
based on fR3lm
Output for 7.3.0rc3
Warning: array_diff_assoc(): Expected parameter 1 to be an array, null given in /in/l9CdP on line 11 bool(true)
Output for 7.0.0 - 7.3.0beta1
Warning: array_diff_assoc(): Argument #1 is not an array in /in/l9CdP on line 11 bool(true)
Output for 5.6.0 - 5.6.25
Catchable fatal error: Argument 1 passed to isLikeThis() must be an instance of string, string given, called in /in/l9CdP on line 13 and defined in /in/l9CdP on line 5
Process exited with code 255.