Home  >  Article  >  Backend Development  >  phpObject(Object)

phpObject(Object)

伊谢尔伦
伊谢尔伦Original
2016-11-24 13:55:431862browse

Object initialization

To create a new object object, instantiate a class using the new statement:

<?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 anything. 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. Converting an array to an object will cause the keys to become property names with corresponding values. For any other value, the member variable named scalar will contain the value.

<?php
$obj = (object) &#39;ciao&#39;;
echo $obj->scalar;  // outputs &#39;ciao&#39;
?>


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
Previous article:php data type NULLNext article:php data type NULL