What is stdClass in PHP?
What is stdClass in PHP?
In PHP, stdClass is a built-in class that represents an object without a defined class. It is commonly used when an object is created without specifying a class or when an object is converted from an array using the (object) cast.
Here are some key points about stdClass in PHP:
When an object is created without specifying a class, PHP automatically creates an instance of stdClass for that object. For example:
$obj = new stdClass();
$obj->name = "John";
$obj->age = 30;
In this case, $obj is an instance of stdClass with two properties: name and age.
stdClass is also used when an array is converted to an object using the (object) cast. For example:
$array = ['name' => 'John', 'age' => 30];
$obj = (object) $array;
Đăng nhập để tham gia thảo luận cùng mọi người.
Chưa có bình luận nào
Hãy là người đầu tiên chia sẻ suy nghĩ của bạn.