Thread: OOP logic??
View Single Post
Old 10-13-2006, 11:53 AM   #9 (permalink)
DJMaze
Senior Contributor
 
DJMaze's Avatar
 
Join Date: Mar 2005
Posts: 733
DJMaze is on a distinguished road
Quote:
Originally Posted by sde
hey djm, isn't there a slick get/set model for PHP 5 classes?
Correct
PHP Code:
<?php

class aphp5class
{
    
# overloaders don't use the private, protected and public member definition
    
function __get($key)
    {
        if (isset(
$this->$key))
        {
            return 
$this->$key;
        }
        else
        {
            throw new 
Exception($key.' does not exist');
        }
    }

    function 
__set($key$value)
    {
        if (isset(
$this->$key))
        {
            
$this->$key $value;
            
mysql_query('UPDATE table SET '.$key.'=\''.$value.'\'');
        }
        else
        {
            throw new 
Exception($key.' does not exist');
        }
    }

}
__________________

UT: Ultra-kill... God like!
DJMaze is offline   Reply With Quote