PHP Static Properties

A quick note that if you instantiate a static class and call a member static method which writes to a member property, PHP will fail without telling you about it. It makes sense why that isn’t legal, but it sucks that it happens without any clue… so it’s a head banger of a problem to find.

class testClass
    private $memberProperty;
    public static function doSchtuff($stuff)
        $this->memberProperty = $stuff;
        return true;
    public function doSomthing($youzaCrazy) {
        return sha1($this->memberProperty.$youzaCrazy);

In this particular problem the solution is to try and keep static and non-static functionality from inter mingling inside the same class. I know that isn’t always a possibility, but I would point to interfaces or inheritance to keep things pleasantly organized.

unfortunately, keeping these sorts of things aren’t always possible… especially when working with massive legacy piles.

Now that my head doesn’t hurt anymore…

This entry was posted in Uncategorized. Bookmark the permalink.

Comments are closed.