Returning a variable
posted by kalprestito on 2010-01-05 13:49:08
Hi.
I thinked this code to get and set private vars in my classes but i don't know if it's correct because i can't set up a localhost.
I thinked this code to get and set private vars in my classes but i don't know if it's correct because i can't set up a localhost.
public function _get ($propname) { if (method_exists($this, "get".$propname)) { return call_user_func("$this->get".$propname); }elseif (property_exists($this, $propname)) { <b>return $this->{$propname};</b> //is this correct??? } } public function _set ($propname, $value) { if (method_exists($this, "set".$propname)) { return call_user_func ("$this->set".$propname, $value); }elseif (property_exists($this, $propname)) { <b>$this->{$propname} = $value;</b> //and this??? $this->_changed = true; } }
0
I checked it. It works!
0
Don't look ↑!
It's all wrong!
1st: get and set overload functions are with two __ not one _
2nd: In call user func we need an array to call a method:3rd: To do what I wanted, this code is needed:This is a very very *VERY* bad code. Sorry.
It's all wrong!
1st: get and set overload functions are with two __ not one _
2nd: In call user func we need an array to call a method:
return call_user_func (array("$this", "set".$propname), $value);
eval("$"."this->".$propname." = $"."value;");
Answer the question
Top Users
- dail (12)
- livin52 (3)
- camu (3)
- softweb (2)
- Nadine (1)
- Josware (1)
- lfelipecr (1)
- gregoriohc (1)
- Mitu (1)
- ryan714 (1)