I want to set attribute for a stdClass object in a single statement. I don\'t have any idea about it. I know the following things
$obj = new stdClass; $
foreach ($attributes as $name => $value) { if (property_exists(self::class, $name)) { $this->{$name} = $value; } }
is cleanest because it will set an arbitrary attribute if you print_r(get_object_vars($obj)) of returned object if attribute does not exist.