Parsing PHP data type objects (Object)

怪我咯
Release: 2023-03-07 10:58:02
Original
5281 people have browsed it

ObjectInitialization

To create a new object object, use The new statement instantiates a class:

<?php
class foo
{
   function do_foo()
   {
       echo "Doing foo.";
   }
}
 
$bar = new foo;
$bar->do_foo();
?>
Copy after login

Convert to object

If you convert an object to an object, it will not change in any way. If a value of any other type is converted to an object, an instance of the built-in class stdClass will be created. If the value is NULL, the new instance is empty. ArrayConvert to object

使键名成为属性名并具有相对应的值。对于任何其它的值,名为 scalar 的成员变量将包含该值。
<?php
$obj = (object) &#39;ciao&#39;;
echo $obj->scalar;  // outputs &#39;ciao&#39;
?>
Copy after login

The above is the detailed content of Parsing PHP data type objects (Object). For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template