Posted by cluthz on 05/07/07 15:06
Hi there,
I'm going to create a class in one of my PHP4 applications for the first
time. However I was reading up about the
__get and __set functions within a class.
Reading about OO / classes I would expect to be able to create a get
function for each public variable.
Therefore if I has class example:
class example {
var $test1;
var $test2;
}
I would expect to be able to add the functions (something like the
following)
__get ($test1) {
#Do stuff with test1
return $this->$test1;
}
__get ($test2) {
#Do stuff with test2
return $this->$test2;
}
But reading about it, it seems that I can only have a single __get function
per class and that within the __get function I have to test for which
variable is being set.
e.g.
__get ($name) {
switch ($name) {
case "test1":
#Do stuff with test1
return $this->$test1;
case "test2":
#Do stuff with test2
return $this->$test3;
case default:
echo "error";
}
}
This is not what I would expect of OO behaviour from what I have read
elsewhere.
Can someone please help me to confirm to me how this works.
Thanks in advance.
Navigation:
[Reply to this message]
|