Q:

Why stdClass is coming instead of our custom object name?

Here My class name is User, When I print my class properties I'm getting my objective name properly. After that, I encoded the data with json_encode(). and then I decoding with json_decode(). I'm getting stdClass objective why?
<?php
class User
{
    public $name;
    public $age;
    public $salary;
}
    $user = new User();
    $user->name = 'Siddhu';
    $user->age = 24;
    $user->salary = 7000.80;

print_r($user);
//Output: User Object ( [name] => Siddhu [age] => 24 [salary] => 7000.8 ) 

print_r(json_encode($user));
//Output: {"name":"Siddhu","age":24,"salary":7000.8}

$d = json_encode($user);

$s = json_decode($d);
print_r($s);
//Output: stdClass Object ( [name] => Siddhu [age] => 24 [salary] => 7000.8 ) 

If you noticed stdClass is coming, How can I change to user

A:

There is no direct way you can get data in class object either you need to used custom method to decode else you can use serialize()  && unserialize() function to get data in the class object when you decode;
$serialized_user_object = serialize($user);

$deserialized_user_object = unserialize($serialized_user_object);

In json_decode you can pass true in second argument if you want data as array.
like this.
var_dump(json_decode($json, true));

to know more about json_decode see here.

A:

The reason this happens can be demonstrated quite easily...
class foo{
    public $bar = 'bar';
}

$json = json_encode(new foo);

echo $json."\n\n";

print_r(json_decode($json));

Output
{"bar":"bar"}

stdClass Object
(
    [bar] => bar
)

Sandbox
As you can see the output {"bar":"bar"} contains no information about what if any class this was, it could have been ['bar'=>'bar'] and the JSON would be the same...  Then when decoding it, you don't have json_decode set to return as an array (second argument set to true), which is fine as that's not really what you want, but when it's set that way you get stdClass objects instead of an associative array for items with non-numeric keys.  In short there is no way to recover the class "foo" from the json {"bar":"bar"} as that information does't exist (you can make it exist, but that's another tale for another day).
Using serialize we get something very different. 
class foo{
    public $bar = 'bar';
}

$json = serialize(new foo);

 echo $json."\n\n";

print_r(unserialize($json));

Output
O:3:"foo":1:{s:3:"bar";s:3:"bar";}

foo Object
(
    [bar] => bar
)

Sandbox
This O:3:foo means an Object with a class name 3 in length named "foo".  So it preserves that information for PHP to use when "decoding" the data.
The whole thing reads like this:
Object (3) "foo" with 1 property named (s)tring (3) "bar" with a value of (s)tring (3) "bar", or something like that.
Make sense.
AS a note PHP's serialize is less portable then JSON, as it only works in PHP,  It's also much harder to manually edit then JSON, but if you really want to encode a class than that is the easiest way to do it.  That said you can also "repopulate" the class from JSON data, but that can also be hard to maintain.

