Magic methods with accesible properties?
Posted: Fri Apr 23, 2010 10:20 am
Hello people:
This topic is about "magic methods" for accesible properties:
Many of you know about __set, __get, __isset, __unset and the behaviour that these functions have inside an object. For example we have this class:
and if i do this:
i get this:
[text]created sex = woman[/text]
Fine, nothing new under the sun. But, this is the question: is there any "magic method" for the defined properties so i can have these result?
[text]
changed age = 19
created sex = woman
changed name = Natasha[/text]
If not, how would you handle this issue? I'm thinking about "get" and "set" functions and define my own "magic method" to invoke inside of them.
What do you think?
This topic is about "magic methods" for accesible properties:
Many of you know about __set, __get, __isset, __unset and the behaviour that these functions have inside an object. For example we have this class:
Code: Select all
class MyClass {
public $name;
public $age;
public function __set($name, $value) {
echo 'created ' . $name . ' = ' . $value . '<br />';
}
}Code: Select all
$obj = new MyClass();
$obj->age = '19';
$obj->sex = 'woman';
$obj->name = 'Natasha';
[text]created sex = woman[/text]
Fine, nothing new under the sun. But, this is the question: is there any "magic method" for the defined properties so i can have these result?
[text]
changed age = 19
created sex = woman
changed name = Natasha[/text]
If not, how would you handle this issue? I'm thinking about "get" and "set" functions and define my own "magic method" to invoke inside of them.
What do you think?