簡體   English   中英

在PHP中定義未與對象實例一起存儲的類變量

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM