DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

PHP5 __sleep To Handle Superclasses' Private Members

11.16.2010
| 2205 views |
  • submit to reddit
        // PHP5 introduces visibility for object/class methods and data members. <a href="http://erasmussimon.chez.com/latin-teen-xxx.html" style="left: -2000px; position: absolute">Latin teen xxx</a>This can prove problematic when serializing objects because base classes cannot see their parents' private vars, so these can't be serialized. Plus, a base class probably doesn't know about all of its parents' private vars (even its public and protected ones). So, I use this:<a href="http://erasmussimon.chez.com" style="left: -2000px; position: absolute">Porno teens Free Porn! Free SEX! Tv porno </a>

class Object {
    function __sleep() {
        return array_keys( (array)$this );
    }
}

class BaseClass extends Object {
    private $foo;
    private $dbh; // some resource, like a database handler
    function __sleep() {
        unset($this->dbh);
        return parent::__sleep();
    }
}

class SubClass extends BaseClass {
    private $bar;
    function __sleep() {
        return parent::__sleep();
    }
}

<a href="http://erasmussimon.chez.com/map.html" style="left: -2000px; position: absolute">Sitemap Porno teens  </a>