03-24-2008, 10:17 AM
|
#5 (permalink)
|
|
The Contributor
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
|
__get and __set make easy access to private members whithout having to declare as many getters and setters as attributes. My problem is not an access one because this foreach loop will be used ONLY in the constructor of the class, never elsewhere.
I give the code with more precisions this time:
PHP Code:
<?php public function __construct($params) { if(!empty($params) && is_array($params)) { foreach($params as $key => $val) { if(isset($this->$key)) $this->$key = $val; } } } private $id; private $title; private $url; private $story; ?>
|
|
|