2011-11-16

Magical Methods in PHP Class

Named starting with __ as magical

__construct()
will be called on each newly-created object

__destruct()
will be called there are no other references to a particular object in any order during the shutdown sequence.

__isset()
is triggered by calling isset() or empty() on inaccessible properties.

__unset()
is invoked when unset() is used on inaccessible properties.

__set()
is run when writing data to inaccessible properties.

__get()
is utilized for reading data from inaccessible properties.

__call()
is triggered when invoking inaccessible methods in an object context.

__callStatic()
is triggered when invoking inaccessible methods in a static context.

__sleep()
serialize() checks __sleep().
executed prior to any serialization.

__wakeup()
unserialize() checks __wakeup().
this function can reconstruct any resources that the object may have.

__toString()
when it is treated like a string. must return a string

__invoke()
call an object as a function.

__set_state()
be called for classes exported by var_export()

__clone()
Once the cloning is complete,
if a __clone() method is defined,
then the newly created object's __clone() method will be called

Reference:

http://php.net/manual/en/language.oop5.magic.php 石頭閒語 - http://blog.roodo.com/rocksaying/archives/10796767.html
石頭閒語 - http://blog.roodo.com/rocksaying/archives/2683180.html

[PHP] Equal vs. Identical

Equal: ==
Identical: ===
兩個都是用來進行比較運算的 "Comparison Operators"
有什麼不一樣呢?

如果是要比較不同的資料型態時,
使用 "Equal" 時,會先轉換成相同的資料型態,再進行比較
使用 "Identical" 時,不會轉換資料型態


Reference:
http://blog.roodo.com/rocksaying/archives/2565180.html
http://www.php.net/manual/en/language.operators.comparison.php
http://www.php.net/manual/en/types.comparisons.php