string to attribute name in PHP classs

Discussion in 'PHP' started by mnaghdi, Nov 15, 2009.

  1. #1
    Hi

    This works fine:
    
    echo $xml -> value;
    PHP:
    but this doesn't:
    
    $v = "value";
    echo $xml -> $v;
    PHP:
    I'd get this error:
    Notice: Array to string conversion in...

    How can I change that string so php interprets it to an attribute name?
     
    mnaghdi, Nov 15, 2009 IP
  2. JAY6390

    JAY6390 Peon

    Messages:
    918
    Likes Received:
    31
    Best Answers:
    0
    Trophy Points:
    0
    #2
    echo $xml->{$value};

    try that
     
    JAY6390, Nov 15, 2009 IP
  3. joebert

    joebert Well-Known Member

    Messages:
    2,150
    Likes Received:
    88
    Best Answers:
    0
    Trophy Points:
    145
    #3
    Are you suer you're using the exact same code you posted, or are you using a pseudo example ?
    That should work as-is.
     
    joebert, Nov 15, 2009 IP