Thread: array to object
View Single Post
Old 03-24-2008, 10:17 AM   #5 (permalink)
Gibou
The Contributor
 
Gibou's Avatar
 
Join Date: Nov 2007
Location: France, near Paris
Posts: 53
Thanks: 6
Gibou is on a distinguished road
Default

__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;
?>
__________________
Wedus project's Website
Send a message via MSN to Gibou
Gibou is offline  
Reply With Quote