phpObject(Object)

伊谢尔伦
Release: 2016-11-24 13:55:43
Original
1808 people have browsed it

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

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;
?>
Copy after login


Related labels:
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
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!