note 97571 added to language.oop5.overloading

From: Date: Mon, 26 Apr 2010 19:30:06 +0000
Subject: note 97571 added to language.oop5.overloading
Groups: php.notes 
Request: Send a blank email to php-notes+get-168674@lists.php.net to get a copy of this message
I've written a brief, generic function for __get() and __set() that works well implementing accessor and mutator functions. This allows the programmer to use implicit accessor and mutator methods when working with attribute data. <?php class MyClass { private $degrees public function __get($name) { $fn_name = 'get_' . $name; if (method_exists($this, $fn_name)) { return $this->$fn_name(); } else { return null; } } public function __set($name, $value) { $fn_name = 'set_' . $name; if (method_exists($this, $fn_name)) { $this->$fn_name($value); } } private function get_degrees() { return $this->degrees; } private function set_degrees($value) { $this->degrees = $value % 360; if ($degrees < 0) $this->degrees += 360; } } ?> ---- Server IP: 69.147.83.197 Probable Submitter: 129.21.28.8 ---- Manual Page -- http://www.php.net/manual/en/language.oop5.overloading.php Edit -- https://master.php.net/note/edit/97571 Del: integrated -- https://master.php.net/note/delete/97571/integrated Del: useless -- https://master.php.net/note/delete/97571/useless Del: bad code -- https://master.php.net/note/delete/97571/bad+code Del: spam -- https://master.php.net/note/delete/97571/spam Del: non-english -- https://master.php.net/note/delete/97571/non-english Del: in docs -- https://master.php.net/note/delete/97571/in+docs Del: other reasons-- https://master.php.net/note/delete/97571 Reject -- https://master.php.net/note/reject/97571 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#168674) next »