<?php
class Example {
private $name;
}
$obj = new Example();
$str = '{"name": "test"}';
function set_value($object, $key, $value) {
$object->$key = $value;
}
foreach (json_decode($str, true) as $k => $v) {
set_value($obj, $k, $v);
}
var_dump($obj);