Link to home
Start Free TrialLog in
Avatar of DJ_AM_Juicebox
DJ_AM_Juicebox

asked on

PHP + properties

Hi,

If I understand properties (PHP 5+) correctly, your class has one __set() and one __get() method, like:

function __get($propName) {
    if ($propName == 'size') {
       ...
    }
    else if ($propName == 'height') {
        ...
    }
}

function __set($propName, $value) {
    if ($propName == 'size') {
       ...
    }
    else if ($propName == 'height') {
        ...
    }
}


How does that scale once you start getting a lot of properties in your class? It seems similar to doing a linear search in an array.

Thanks
ASKER CERTIFIED SOLUTION
Avatar of Rob Siklos
Rob Siklos
Flag of Canada image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
The above is obviously a trivial example, but it's great because you can handle new properties without modifying any code, and you can change the implementation or add error checking without changing the API you expose.
Avatar of DJ_AM_Juicebox
DJ_AM_Juicebox

ASKER

I see, thanks.