SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Member
    Join Date
    Jul 2008
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    dynamic initialization of a class variable

    Happy new year 2009 to all.

    Hi I am a little bit messed up when I wanted to initialize some dynamic variables but I ended up getting messed up and getting no output. Please suggest me if it is doable or not.


    Code PHP:
    foreach($_REQUEST as $key ){			
      $this->$key = $_REQUEST['$key'];
    }

    Thanks in advance.
    Last edited by niranjannp; Jan 2, 2009 at 19:56. Reason: code formatting

  2. #2
    Guru in training bronze trophy SoulScratch's Avatar
    Join Date
    Apr 2006
    Location
    Maryland
    Posts
    1,838
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Anything inside single quotes isn't interpolated, perhaps you should try "$key" ?
    Cross browser css bugs

    Dan Schulz you will be missed

  3. #3
    Use The Cloud
    Join Date
    Jan 2006
    Location
    Boise, ID
    Posts
    556
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by SoulScratch View Post
    Anything inside single quotes isn't interpolated, perhaps you should try "$key" ?
    $key is not a key anyway, it's a value.

    Maybe something like this?

    PHP Code:
    foreach ($_REQUEST as $key => $value) {
        
    $this->$key $value;

    Brad Hanson, Web Applications & Scalability Specialist
    ► Is your website outgrowing its current hosting solution?
    ► PM me for a FREE scalability consult!
    ► USA Based: Available by Phone, Skype, AIM, and E-mail.


Tags for this Thread

Bookmarks

Posting Permissions

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