![](/img/trans.png)
[英]How to define a PHP variable as a specific class type before instantiate an object?
[英]Define class variable in PHP that is not stored along with the object instance
我有一堂簡單的課:
class obj__image extends obj__file {
public $dimensions;
public $storedDPI;
public $colorProfile;
}
例如,當我將此實例存儲到會話中時,該對象將被序列化並存儲起來。 沒關系。
但是,有什么方法可以定義一個類變量,例如上面的$colorProfile
以便在存儲/序列化對象時不將其存儲?
您可以通過為該類定義魔術__sleep()方法來精確控制序列化對象中包含哪些屬性。 __sleep()方法應返回一個屬性名稱數組:該數組中列出的那些屬性名稱將包含在序列化對象中,所有其他未列出的屬性將被丟棄
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.