亚洲国产日韩欧美一区二区三区,精品亚洲国产成人av在线,国产99视频精品免视看7,99国产精品久久久久久久成人热,欧美日韩亚洲国产综合乱

Table of Contents
Table of Contents
Previous words
Construction method
Destruction method
Inaccessible property
Object copy
String
Object does not exist
Automatic loading of classes
串行化
函數(shù)調(diào)用
Home php教程 php手冊 The second magic method in the object-oriented series of front-end learning PHP

The second magic method in the object-oriented series of front-end learning PHP

Nov 16, 2016 am 10:24 AM

×
Table of Contents
[1] Construction method [2] Destruction method [3] Inaccessible properties [4] Object copy [5] String [6] Object does not exist [7] Automatic loading of classes [8] Serialization [9] Function call

Previous words

  PHP has many related magic methods in the object-oriented part. These methods provide convenience for object-oriented implementation. This article will introduce the magic methods in detail

Construction method

 Most classes have a special method called a constructor. When an object is created, it will automatically call the constructor, which is usually used to perform some useful initialization tasks

 The declaration of a constructor is the same as the declaration of other operations, except that its name must be two underscores __construct(). This is a change in PHP5; in the PHP4 version, the name of the constructor must be the same as the class name. For backward compatibility, if there is no method named __construct() in a class, PHP will search for a method with the same name as the class

void __construct ([ <span style="color: #0000ff;">mixed</span> <span style="color: #800080;">$args</span> [, $... ]] )

 If a constructor is defined in a subclass, the constructor of its parent class will not be implicitly called. To execute the parent class's constructor, you need to call parent::__construct() in the child class's constructor. If the subclass does not define a constructor, it will be inherited from the parent class like a normal class method (if it is not defined as private)

<?<span style="color: #000000;">php
</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> BaseClass {
   </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> __construct() {
       </span><span style="color: #0000ff;">print</span> "In BaseClass constructor\n"<span style="color: #000000;">;
   }
}
</span><span style="color: #0000ff;">class</span> SubClass <span style="color: #0000ff;">extends</span><span style="color: #000000;"> BaseClass {
   </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> __construct() {
       parent</span>::<span style="color: #000000;">__construct();
       </span><span style="color: #0000ff;">print</span> "In SubClass constructor\n"<span style="color: #000000;">;
   }
}
</span><span style="color: #0000ff;">class</span> OtherSubClass <span style="color: #0000ff;">extends</span><span style="color: #000000;"> BaseClass {
}
</span><span style="color: #008000;">//</span><span style="color: #008000;"> In BaseClass constructor</span>
<span style="color: #800080;">$obj</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> BaseClass();

</span><span style="color: #008000;">//</span><span style="color: #008000;"> In BaseClass constructor
// In SubClass constructor</span>
<span style="color: #800080;">$obj</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> SubClass();

</span><span style="color: #008000;">//</span><span style="color: #008000;"> In BaseClass constructor</span>
<span style="color: #800080;">$obj</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> OtherSubClass();
</span>?>

Destruction method

 The opposite of the construction method is the destruction method. The destructor method is a newly added content of PHP5. There is no destructor method in PHP4. The destructor method is a method that is automatically called before the object is destroyed. It mainly performs some specific operations, such as closing files, releasing result sets, etc.

 Similar to the constructor method, the destructor method name of a class must be two underscores _ _destruct(). Destructor cannot take any parameters

<?<span style="color: #000000;">php
</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> MyDestructableClass {
   </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> __construct() {
       </span><span style="color: #0000ff;">print</span> "In constructor\n"<span style="color: #000000;">;
       </span><span style="color: #800080;">$this</span>->name = "MyDestructableClass"<span style="color: #000000;">;
   }
   </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> __destruct() {
       </span><span style="color: #0000ff;">print</span> "Destroying " . <span style="color: #800080;">$this</span>->name . "\n"<span style="color: #000000;">;
   }
}
</span><span style="color: #008000;">//</span><span style="color: #008000;">In constructor Destroying MyDestructableClass</span>
<span style="color: #800080;">$obj</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> MyDestructableClass();
</span>?>

Inaccessible property

get()

When reading inaccessible attributes (protected, private), __get() will be called, and the attribute name will be passed into this method as the first parameter (string)

<span style="color: #0000ff;">public</span> <span style="color: #0000ff;">mixed</span> __get ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$name</span> )
<?<span style="color: #000000;">php
</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> demo{
    </span><span style="color: #0000ff;">protected</span> <span style="color: #800080;">$protected</span> = 1<span style="color: #000000;">;
    </span><span style="color: #0000ff;">public</span> <span style="color: #800080;">$public</span> = 2<span style="color: #000000;">;
    </span><span style="color: #0000ff;">private</span> <span style="color: #800080;">$private</span> = 3<span style="color: #000000;">;
    </span><span style="color: #0000ff;">function</span> __get(<span style="color: #800080;">$name</span><span style="color: #000000;">){
        </span><span style="color: #0000ff;">echo</span> "111{<span style="color: #800080;">$name</span>}111<br>"<span style="color: #000000;">;
    }
}
</span><span style="color: #800080;">$d1</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> demo;
</span><span style="color: #800080;">$d1</span>-><span style="color: #0000ff;">protected</span>;<span style="color: #008000;">//</span><span style="color: #008000;">111protected111</span>
<span style="color: #800080;">$d1</span>-><span style="color: #0000ff;">public</span><span style="color: #000000;">;
</span><span style="color: #800080;">$d1</span>-><span style="color: #0000ff;">private</span>;<span style="color: #008000;">//</span><span style="color: #008000;">111private111</span>
?>

set()

When assigning a value to an inaccessible attribute (protected, private), __set() will be called, and the attribute name will be passed into this method as the first parameter (string) and the value as the second parameter (mixed)

<span style="color: #0000ff;">public</span> void __set ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$name</span> , <span style="color: #0000ff;">mixed</span> <span style="color: #800080;">$value</span> )
<?<span style="color: #000000;">php
</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> demo{
    </span><span style="color: #0000ff;">protected</span> <span style="color: #800080;">$protected</span> = 1<span style="color: #000000;">;
    </span><span style="color: #0000ff;">public</span> <span style="color: #800080;">$public</span> = 2<span style="color: #000000;">;
    </span><span style="color: #0000ff;">private</span> <span style="color: #800080;">$private</span> = 3<span style="color: #000000;">;
    </span><span style="color: #0000ff;">function</span> __set(<span style="color: #800080;">$name</span>,<span style="color: #800080;">$value</span><span style="color: #000000;">){
        </span><span style="color: #0000ff;">echo</span> "0{<span style="color: #800080;">$name</span>}0{<span style="color: #800080;">$value</span>}<br>"<span style="color: #000000;">;
    }
}
</span><span style="color: #800080;">$d1</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> demo;
</span><span style="color: #800080;">$d1</span>-><span style="color: #0000ff;">protected</span> = '1';<span style="color: #008000;">//</span><span style="color: #008000;">0protected01</span>
<span style="color: #800080;">$d1</span>-><span style="color: #0000ff;">public</span> = '2'<span style="color: #000000;">;
</span><span style="color: #800080;">$d1</span>-><span style="color: #0000ff;">private</span> = '3';<span style="color: #008000;">//</span><span style="color: #008000;">0private03</span>
?>

isset()

 When isset() or empty() is called on inaccessible properties (protected, private), __isset() will be called

<span style="color: #0000ff;">public</span> bool __isset ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$name</span> )
<?<span style="color: #000000;">php
</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> demo{
    </span><span style="color: #0000ff;">protected</span> <span style="color: #800080;">$protected</span> = 1<span style="color: #000000;">;
    </span><span style="color: #0000ff;">public</span> <span style="color: #800080;">$public</span> = 2<span style="color: #000000;">;
    </span><span style="color: #0000ff;">private</span> <span style="color: #800080;">$private</span> = 3<span style="color: #000000;">;
    </span><span style="color: #0000ff;">function</span> __isset(<span style="color: #800080;">$name</span><span style="color: #000000;">){
        </span><span style="color: #0000ff;">echo</span> "0{<span style="color: #800080;">$name</span>}0<br>"<span style="color: #000000;">;
    }
}
</span><span style="color: #800080;">$d1</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> demo;
</span><span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$d1</span>-><span style="color: #0000ff;">protected</span>);<span style="color: #008000;">//</span><span style="color: #008000;">0protected0</span>
<span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$d1</span>-><span style="color: #0000ff;">public</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">empty</span>(<span style="color: #800080;">$d1</span>-><span style="color: #0000ff;">private</span>);<span style="color: #008000;">//</span><span style="color: #008000;">0private0</span>
?>

unset()

 When unset() is called on inaccessible properties (protected, private), __unset() will be called

<span style="color: #0000ff;">public</span> void __unset ( <span style="color: #0000ff;">string</span> <span style="color: #800080;">$name</span> )
<?<span style="color: #000000;">php
</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> demo{
    </span><span style="color: #0000ff;">protected</span> <span style="color: #800080;">$protected</span> = 1<span style="color: #000000;">;
    </span><span style="color: #0000ff;">public</span> <span style="color: #800080;">$public</span> = 2<span style="color: #000000;">;
    </span><span style="color: #0000ff;">private</span> <span style="color: #800080;">$private</span> = 3<span style="color: #000000;">;
    </span><span style="color: #0000ff;">function</span> __unset(<span style="color: #800080;">$name</span><span style="color: #000000;">){
        </span><span style="color: #0000ff;">echo</span> "0{<span style="color: #800080;">$name</span>}0<br>"<span style="color: #000000;">;
    }
}
</span><span style="color: #800080;">$d1</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> demo;
</span><span style="color: #0000ff;">unset</span>(<span style="color: #800080;">$d1</span>-><span style="color: #0000ff;">protected</span>);<span style="color: #008000;">//</span><span style="color: #008000;">0protected0</span>
<span style="color: #0000ff;">unset</span>(<span style="color: #800080;">$d1</span>-><span style="color: #0000ff;">public</span><span style="color: #000000;">);
</span><span style="color: #0000ff;">unset</span>(<span style="color: #800080;">$d1</span>-><span style="color: #0000ff;">private</span>);<span style="color: #008000;">//</span><span style="color: #008000;">0private0</span>
?>

Object copy

clone()

 The clone() method is automatically called when an object is cloned. This method does not require any parameters. You can use this method to reinitialize the cloned copy

 The clone() method will automatically include references to two objects, this and that. This is a reference to the copy object, and that is a reference to the original object

<?<span style="color: #000000;">php
    </span><span style="color: #0000ff;">class</span><span style="color: #000000;"> Person{
        </span><span style="color: #0000ff;">private</span> <span style="color: #800080;">$name</span><span style="color: #000000;">;
        </span><span style="color: #0000ff;">private</span> <span style="color: #800080;">$sex</span><span style="color: #000000;">;
        </span><span style="color: #0000ff;">private</span> <span style="color: #800080;">$age</span><span style="color: #000000;">;
        </span><span style="color: #0000ff;">function</span> __construct(<span style="color: #800080;">$name</span>="",<span style="color: #800080;">$sex</span>="",<span style="color: #800080;">$age</span>=1<span style="color: #000000;">){
            </span><span style="color: #800080;">$this</span>->name= <span style="color: #800080;">$name</span><span style="color: #000000;">;
            </span><span style="color: #800080;">$this</span>->sex = <span style="color: #800080;">$sex</span><span style="color: #000000;">;
            </span><span style="color: #800080;">$this</span>->age = <span style="color: #800080;">$age</span><span style="color: #000000;">;
        }
        </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> __clone(){
            </span><span style="color: #800080;">$this</span>->name = <span style="color: #800080;">$this</span>->name."的副本"<span style="color: #000000;">;
        }
        </span><span style="color: #0000ff;">function</span><span style="color: #000000;"> say(){
            </span><span style="color: #0000ff;">echo</span> "我的名字:" .<span style="color: #800080;">$this</span>->name.",性別:".<span style="color: #800080;">$this</span>->sex.",年齡:".<span style="color: #800080;">$this</span>->age."<br>"<span style="color: #000000;">;
        }
    }
    </span><span style="color: #800080;">$p1</span> = <span style="color: #0000ff;">new</span> Person('張三','男','20'<span style="color: #000000;">);
    </span><span style="color: #800080;">$p2</span> = <span style="color: #0000ff;">clone</span> <span style="color: #800080;">$p1</span><span style="color: #000000;">;
    </span><span style="color: #800080;">$p1</span>->say();<span style="color: #008000;">//</span><span style="color: #008000;">我的名字:張三,性別:男,年齡:20</span>
    <span style="color: #800080;">$p2</span>->say();<span style="color: #008000;">//</span><span style="color: #008000;">我的名字:張三的副本,性別:男,年齡:20</span>
?>

String

toString()

 The __toString() method is used to determine how a class should respond when it is treated as a string. It is the most convenient way to quickly obtain the string representation of an object. It is a method that is automatically called when directly outputting an object reference

<?<span style="color: #000000;">php
</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> TestClass
{
    </span><span style="color: #0000ff;">public</span> <span style="color: #800080;">$foo</span><span style="color: #000000;">;
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> __construct(<span style="color: #800080;">$foo</span><span style="color: #000000;">) 
    {
        </span><span style="color: #800080;">$this</span>->foo = <span style="color: #800080;">$foo</span><span style="color: #000000;">;
    }
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> __toString() {
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$this</span>-><span style="color: #000000;">foo;
    }
}
</span><span style="color: #800080;">$class</span> = <span style="color: #0000ff;">new</span> TestClass('Hello'<span style="color: #000000;">);
</span><span style="color: #0000ff;">echo</span> <span style="color: #800080;">$class</span>;<span style="color: #008000;">//</span><span style="color: #008000;">Hello</span>
?>

Object does not exist

call()

 When an inaccessible method is called in an object, __call() will be called

callStatic()

 When calling an inaccessible method in a static context, __callStatic() will be called

<?<span style="color: #000000;">php
</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> MethodTest 
{
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> __call(<span style="color: #800080;">$name</span>, <span style="color: #800080;">$arguments</span><span style="color: #000000;">) 
    {
        </span><span style="color: #0000ff;">echo</span> "Calling object method '<span style="color: #800080;">$name</span>' "
             . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$arguments</span>). "\n"<span style="color: #000000;">;
    }
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">function</span> __callStatic(<span style="color: #800080;">$name</span>, <span style="color: #800080;">$arguments</span><span style="color: #000000;">) 
    {
        </span><span style="color: #0000ff;">echo</span> "Calling static method '<span style="color: #800080;">$name</span>' "
             . <span style="color: #008080;">implode</span>(', ', <span style="color: #800080;">$arguments</span>). "\n"<span style="color: #000000;">;
    }
}
</span><span style="color: #800080;">$obj</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> MethodTest;
</span><span style="color: #008000;">//</span><span style="color: #008000;">Calling object method 'runTest' in object context</span>
<span style="color: #800080;">$obj</span>->runTest('in object context'<span style="color: #000000;">);
</span><span style="color: #008000;">//</span><span style="color: #008000;">Calling static method 'runTest' in static context</span>
MethodTest::runTest('in static context'<span style="color: #000000;">);  
</span>?>

Automatic loading of classes

autoload()

 In PHP5, you can define an __autoload() function, which will be automatically called when trying to use a class that has not yet been defined. By calling this function, the script engine has a last chance to load the required classes before PHP fails with an error

<?<span style="color: #000000;">php
</span><span style="color: #0000ff;">function</span> __autoload(<span style="color: #800080;">$class_name</span><span style="color: #000000;">) {
    </span><span style="color: #0000ff;">require_once</span> <span style="color: #800080;">$class_name</span> . '.php'<span style="color: #000000;">;
}

</span><span style="color: #800080;">$obj</span>  = <span style="color: #0000ff;">new</span><span style="color: #000000;"> MyClass1();
</span><span style="color: #800080;">$obj2</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> MyClass2();
</span>?>

?

串行化

sleep()

  在調(diào)用serialize()函數(shù)將對象串行化時,檢查類中是否存在一個魔術方法 __sleep()。如果存在,該方法會先被調(diào)用,然后才執(zhí)行序列化操作。此功能可以用于清理對象,并返回一個包含對象中所有應被序列化的變量名稱的數(shù)組。如果該方法未返回任何內(nèi)容,則 NULL 被序列化,并產(chǎn)生一個 E_NOTICE 級別的錯誤

  __sleep()函數(shù)不需要接受任何參數(shù),但需要返回一個數(shù)組,在數(shù)組中包含需要串行化的屬性。未被包含在數(shù)組中的屬性將在串行化時被忽略。如果沒有在類中聲明__sleep()方法,對象中的所有屬性都將被串行化

wakeup()

  在調(diào)用unserialize()函數(shù)將對象反串行化對象時,則會自動調(diào)用對象中的__wakeup()方法,用來在二進制串重新組成一個對象時,為新對象中的成員屬性重新初始化

  wakeup()經(jīng)常用在反序列化操作中,例如重新建立數(shù)據(jù)庫連接,或執(zhí)行其它初始化操作

<?<span style="color: #000000;">php
</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> Connection 
{
    </span><span style="color: #0000ff;">protected</span> <span style="color: #800080;">$link</span><span style="color: #000000;">;
    </span><span style="color: #0000ff;">private</span> <span style="color: #800080;">$server</span>, <span style="color: #800080;">$username</span>, <span style="color: #800080;">$password</span>, <span style="color: #800080;">$db</span><span style="color: #000000;">;  
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span> __construct(<span style="color: #800080;">$server</span>, <span style="color: #800080;">$username</span>, <span style="color: #800080;">$password</span>, <span style="color: #800080;">$db</span><span style="color: #000000;">)
    {
        </span><span style="color: #800080;">$this</span>->server = <span style="color: #800080;">$server</span><span style="color: #000000;">;
        </span><span style="color: #800080;">$this</span>->username = <span style="color: #800080;">$username</span><span style="color: #000000;">;
        </span><span style="color: #800080;">$this</span>->password = <span style="color: #800080;">$password</span><span style="color: #000000;">;
        </span><span style="color: #800080;">$this</span>->db = <span style="color: #800080;">$db</span><span style="color: #000000;">;
        </span><span style="color: #800080;">$this</span>-><span style="color: #000000;">connect();
    }
    </span><span style="color: #0000ff;">private</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> connect()
    {
        </span><span style="color: #800080;">$this</span>->link = <span style="color: #008080;">mysql_connect</span>(<span style="color: #800080;">$this</span>->server, <span style="color: #800080;">$this</span>->username, <span style="color: #800080;">$this</span>-><span style="color: #000000;">password);
        </span><span style="color: #008080;">mysql_select_db</span>(<span style="color: #800080;">$this</span>->db, <span style="color: #800080;">$this</span>-><span style="color: #000000;">link);
    }
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> __sleep()
    {
        </span><span style="color: #0000ff;">return</span> <span style="color: #0000ff;">array</span>('server', 'username', 'password', 'db'<span style="color: #000000;">);
    }
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">function</span><span style="color: #000000;"> __wakeup()
    {
        </span><span style="color: #800080;">$this</span>-><span style="color: #000000;">connect();
    }
}
</span>?>

?

函數(shù)調(diào)用

invoke()

  當嘗試以調(diào)用函數(shù)的方式調(diào)用一個對象時,__invoke()方法會被自動調(diào)用

<?<span style="color: #000000;">php
</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> CallableClass 
{
    </span><span style="color: #0000ff;">function</span> __invoke(<span style="color: #800080;">$x</span><span style="color: #000000;">) {
        </span><span style="color: #008080;">var_dump</span>(<span style="color: #800080;">$x</span><span style="color: #000000;">);
    }
}
</span><span style="color: #800080;">$obj</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> CallableClass;
</span><span style="color: #800080;">$obj</span>(5);<span style="color: #008000;">//</span><span style="color: #008000;">int(5)</span>
<span style="color: #008080;">var_dump</span>(<span style="color: #008080;">is_callable</span>(<span style="color: #800080;">$obj</span>));<span style="color: #008000;">//</span><span style="color: #008000;">bool(true)</span>
?>

【補充】

set_state()

  當調(diào)用var_export()導出類時,set_state()方法會被調(diào)用,本方法的唯一參數(shù)是一個數(shù)組,其中包含按 array('property' => value, ...) 格式排列的類屬性

  [注意]var_export()返回關于傳遞給該函數(shù)的變量的結構信息,它和var_dump()類似,不同的是其返回的表示是合法的PHP代碼,也就是說,var_export返回的代碼,可以直接當作php代碼賦給一個變量。 而這個變量就會取得和被var_export一樣的類型的值

<?<span style="color: #000000;">php
</span><span style="color: #0000ff;">class</span><span style="color: #000000;"> A
{
    </span><span style="color: #0000ff;">public</span> <span style="color: #800080;">$var1</span><span style="color: #000000;">;
    </span><span style="color: #0000ff;">public</span> <span style="color: #800080;">$var2</span><span style="color: #000000;">;
    </span><span style="color: #0000ff;">public</span> <span style="color: #0000ff;">static</span> <span style="color: #0000ff;">function</span> __set_state(<span style="color: #800080;">$an_array</span><span style="color: #000000;">) 
    {
        </span><span style="color: #800080;">$obj</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> A;
        </span><span style="color: #800080;">$obj</span>->var1 = <span style="color: #800080;">$an_array</span>['var1'<span style="color: #000000;">];
        </span><span style="color: #800080;">$obj</span>->var2 = <span style="color: #800080;">$an_array</span>['var2'<span style="color: #000000;">];
        </span><span style="color: #0000ff;">return</span> <span style="color: #800080;">$obj</span><span style="color: #000000;">;
    }
}
</span><span style="color: #800080;">$a</span> = <span style="color: #0000ff;">new</span><span style="color: #000000;"> A;
</span><span style="color: #800080;">$a</span>->var1 = 5<span style="color: #000000;">;
</span><span style="color: #800080;">$a</span>->var2 = 'foo'<span style="color: #000000;">;
</span><span style="color: #0000ff;">eval</span>('$b = ' . <span style="color: #008080;">var_export</span>(<span style="color: #800080;">$a</span>, <span style="color: #0000ff;">true</span>) . ';'<span style="color: #000000;">); 
</span><span style="color: #008000;">/*</span><span style="color: #008000;">
object(A)[2]
  public 'var1' => int 5
  public 'var2' => string 'foo' (length=3)
 </span><span style="color: #008000;">*/</span>
<span style="color: #008080;">var_dump</span>(<span style="color: #800080;">$b</span><span style="color: #000000;">);
</span>?>
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

Hot AI Tools

Undress AI Tool

Undress AI Tool

Undress images for free

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

Hot Topics

PHP Tutorial
1488
72