www.webdeveloper.com
Results 1 to 2 of 2

Thread: what is wrong with this code ?

  1. #1
    Join Date
    Feb 2006
    Posts
    54

    resolved what is wrong with this code ?

    Hi. I have this code from a class.
    PHP Code:
    class User    {
        protected 
    $data=array(
            
    'id'=>null,
            
    'username'=>null,
            
    'passwrd'=>null,
            
    'email'=>null,
            
    'lastAccess'=>null,
            
    'firstname'=>null,
            
    'lastname'=>null,
            
    'active'=>null,
            
    'type'=>null,
            
    'hash'=>null
        
        
    );

    public function 
    __construct()    { }
        
        
    public static function 
    assemble(array $data)    {
        foreach (
    $data as $n=>$v)    {
            
    $userObj=new User();
            if (
    in_array($n,array_keys($userObj->data)))    {
                
                
    $userObj->data[$n]=$v;
            }
        }
        
    var_dump($userObj);
        die();
        return 
    $userObj;
    }

    The "assemble" function it's used in this way in my program : $userObj=User::assemble($_POST). Its purpose is to construct an User object with the values fetched from the array i pass as a parameter.
    I get no error during execution, but the function doesn't do its job.
    Can you tell me how to fix the code in order to work?

    EDIT: The problem was that i instantiated the User object inside the foreach loop. It's figured it out now, so if it's possible please delete this post.
    Last edited by orreip; 01-13-2007 at 04:05 PM. Reason: can somebody please delete the post

  2. #2
    Join Date
    Aug 2004
    Location
    Ankh-Morpork
    Posts
    19,634
    EDIT: The problem was that i instantiated the User object inside the foreach loop. It's figured it out now, so if it's possible please delete this post.
    As the thread originator, you can just mark it "resolved" yourself: at the top of the thread select "Thread Tools" and then in the pop-up menu select "Mark Thread Resolved".
    "Please give us a simple answer, so that we don't have to think, because if we think, we might find answers that don't fit the way we want the world to be."
    ~ Terry Pratchett in Nation

    eBookworm.us

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles