View Single Post
Old 07-10-2008, 09:59 AM   #2 (permalink)
sketchMedia
The Prestige
Advanced Programmer Top Contributor Good Samaritan 
 
sketchMedia's Avatar
 
Join Date: Oct 2007
Location: Manchester, UK
Posts: 854
Thanks: 32
sketchMedia is on a distinguished road
Default

Just have accessor methods inside your child classes:
PHP Code:
<?php
class factory
{
    private static 
$pChild;

    public static function 
getInstance($child)
    {
        if(!
self::$pChild instanceof $child
        { 
            
self::$pChild = new $child
        }

        
self::$pChild->someVar 'some value';
        return 
self::$pChild;
    }
}
class 
child
{
    private 
$someVar;

    public function 
__set($key$value)
    {
        if(
in_array($this->$keyget_class_vars(__CLASS__)))
        {
            
$this->$key $value;
        }
    }
    public function 
__get($key)
    {
        if(isset(
$this->$key))
        {
            return 
$this->$key;
        }
        return 
false
    }
}

$child factory::getInstance('child');
echo 
$child->someVar;
That the kind of thing you are after?
__________________
mysql> SELECT * FROM `users` WHERE `users`.`clue` > 0;
Empty set (0.00 sec)
sketchMedia is offline  
Reply With Quote