Advanced features of the 16/7/8_php-object

Source: Internet
Author: User
Tags object serialization

Do not understand this understanding or do not have a clear usage, do not know how to use, after all, still do not understand what is the use. I'm just going to copy it.

Object comparison, when all the properties of two instances of the same class are equal, you can use the comparison operator = = To determine whether a two variable is a reference to the same object, you can use the congruent operator = = =.

Class Car {} $a = new car (), $b = new Car (), if ($a = = $b) echo ' = = ';   Trueif ($a = = = $b) echo ' = = = '; False

Object replication, in some special cases, you can copy an object by using the keyword clone, at which point the __clone method is called, and the value of the property is set by this magic method.

Class Car {public    $name = ' car ';        Public Function __clone () {        $obj = new Car ();        $obj->name = $this->name;    }} $a = new car (), $a->name = ' new car '; $b = clone $a; var_dump ($b);

Object serialization, which can be serialized as a string by the Serialize method, used to store or pass data, and then deserialize the string into an object when needed by Unserialize.

Class Car {public    $name = ' car ';} $a = new Car (); $str = serialize ($a); The object is serialized into a string echo $str. ' <br> '; $b = Unserialize ($STR); Deserializes to Object Var_dump ($b);

Advanced features of the 16/7/8_php-object

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.