Home  >  Article  >  Backend Development  >  Parsing PHP data type objects (Object)

Parsing PHP data type objects (Object)

怪我咯
怪我咯Original
2017-04-05 11:07:185271browse

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();
?>

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;
?>

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!

Statement:
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