NYCPHP Meetup

NYPHP.org

[nycphp-talk] Static variables, self:: and abstract classes

Daniel Convissor danielc at analysisandsolutions.com
Wed Jun 7 10:08:34 EDT 2006


On Wed, Jun 07, 2006 at 07:25:46AM -0500, Andrew Kamm wrote:
> >just one question had crossed my mind right now...
> >
> >why did u had declared the variable as static?
> 
> The idea was to have an abstract parent class for customer preferences since
> most preference classes would basically share the same code.  The static
> vars (or constants) that were to be stored in the individual classes were
> properties that differentiate how the child classes would interact with the
> database (among other things).

Static is the wrong approach.  So scratch what I said in my prior email, I 
was just trying to prove it could be done.

Declare the methods in the parent and the properties in the children.  
Then instantiate your class into an object.  You get your desired outcome 
without a fake constructor plus you don't have to maintain properties in 
the parent that are just going to get overridden.

class base {
    public function getTablename() {
        echo $this->_tablename . "<br/>\n"; 
    }
}

class joes extends base {
    protected $_tablename = 'joestable';
}

$obj = new joes;
$obj->getTablename();

--Dan

-- 
 T H E   A N A L Y S I S   A N D   S O L U T I O N S   C O M P A N Y
            data intensive web and database programming
                http://www.AnalysisAndSolutions.com/
 4015 7th Ave #4, Brooklyn NY 11232  v: 718-854-0335 f: 718-854-0409



More information about the talk mailing list