SQRCAT
SQRCAT

Reputation: 5840

Define class variable in PHP that is not stored along with the object instance

I have a simple class:

class obj__image extends obj__file {

    public $dimensions;
    public $storedDPI;
    public $colorProfile;

}

When i store an instance of this to my session (for example), the object gets serialized and stored away. That's fine.

But is there any way to define a class variable, such as the above $colorProfile so that it will not be stored when storing/serializing the object?

Upvotes: 1

Views: 41

Answers (1)

Mark Baker
Mark Baker

Reputation: 212452

You can control exactly which properties are included in a serialized object by defining a magic __sleep() method for the class. The __sleep() method should return an array of property names: those property names listed in the array will be included in the serialized object, any other unlisted properties will be discarded

Upvotes: 2

Related Questions