Please define what stdClass
is.
相关问题
- Views base64 encoded blob in HTML with PHP
- Laravel Option Select - Default Issue
- PHP Recursively File Folder Scan Sorted by Modific
- Can php detect if javascript is on or not?
- Using similar_text and strpos together
stdClass objects in use
The stdClass allows you to create anonymous classes and with object casting you can also access keys of an associative array in OOP style. Just like you would access the regular object property.
Example
will echo
You can also use
object
to cast arrays to an object of your choice:Now to create an object of type
Example
and to initialize it you can do either of these:OR
The second method is mostly useful for initializing objects with many properties.
stdClass is a another great PHP feature. You can create a anonymous PHP class. Lets check an example.
now think you have a another class that will initialize with a page object and execute base on it.
Now you have to create a new PageShow object with a Page Object.
Here no need to write a new Class Template for this you can simply use stdClass to create a Class on the fly.
Using stdClass you can create a new object with it's own properties. Consider the following example that represents the details of a user as an associative array.
If you need to represent the same details as the properties of an object, you can use stdClass as below.
If you are a Joomla developer refer this example in the Joomla docs for further understanding.