Implement/extend/inherit/... the same __get and __set function for all my classes
<p>I do not like functions like "getProperty" and "setProperty", so I looked into the __get and __set functions.</p>

<p>I created a structure that works quite well. Now I want to use it in most of my classes. How do I do this (keeping in mind I might want to extend a class with another class) without having to duplicate code?</p>

<p>I already know an interface is not an option, as that's all about duplicating code (if I understand it correctly)</p>

<p>Here are the functions, just in case:</p>

<pre><code>/**
 * Simply return the property
 */
private function __get($strProperty) {

    if(array_key_exists($strProperty, $this-&gt;properties)){

        $c = $this-&gt;properties[$strProperty];

        // Fetch the wanted data and store it in memory
        if(!$c['fetched']){

            if($c['type'] == 'array'){
                $proptr = $this-&gt;md-&gt;fetch_array('SELECT ' . $c['field'] . ' FROM ' . $c['table'] . ' WHERE ' . $c['where'], $c['table'].$c['field'].$c['where'], 1000);
                $c['value'] = $proptr;
            }else {
                $proptr = $this-&gt;md-&gt;query_first('SELECT ' . $c['field'] . ' FROM ' . $c['table'] . ' WHERE ' . $c['where'], $c['table'].$c['field'].$c['where'], 1000);
                $c['value'] = $proptr[$c['field']];
            }


        }

        return $c['value'];

    } else {
        return $this-&gt;$strProperty;
    }

}

/**
 * Set the property, and update the database when needed
 */
private function __set($strProperty, $varValue) {

    // If the property is defined in the $properties array, do something special
    if (array_key_exists($strProperty, $this-&gt;properties)) {

        // Get the fieldname
        $field = $this-&gt;properties[$strProperty]['field'];

        $data[$field] = $varValue;

        $this-&gt;md-&gt;update(TABLE_USER, $data, $this-&gt;properties[$strProperty]['where']);

        // And store the value here, too
        $this-&gt;$strProperty = $varValue;

    } else {
        $this-&gt;$strProperty = $varValue;
    }
}
</code></pre>
