2

How to assign value of array to existing object property. I tried this and got error.

 $fieldss = array("name"=>"User Name", "fields"=>"10091437300560754");

 $list = object(stdClass)[325]
   public 'id' => string '1' (length=1)
   public 'form_id' => string '6' (length=1)
   public '10091437300560754' => string 'Ronaldo' (length=9)

 //then I tried to access:
 $list->$fieldss['fields'];    which equals to 'Ronaldo'.
 //but It gives undefined property:$10091437300560754;

Above: $fieldss['fields'] = "10091437300560754"; and $list->$fieldss['fields'] means $list->10091437300560754 but why I get undefined property. Please help.

Updated

I tried my code in localhost with PHP v5.3.8 It worked fine But When I uploaded to server in which PHP v5.4. It gives me error like above

user254153
  • 1,855
  • 4
  • 41
  • 84
  • 2
    [Here](http://stackoverflow.com/questions/10333016/how-to-access-object-properties-with-names-like-integers/10333200#10333200) is an explanation – Rox Jul 23 '15 at 07:21

2 Answers2

0

10091437300560754 is not a valid variable/property name. A valid variable name starts with a letter or underscore, followed by any number of letters, numbers, or underscores.

arbogastes
  • 1,308
  • 9
  • 10
0

I have tried this and it's working fine at my end.

$fieldss = array("name" => "User Name", "fields" => "10091437300560754");

$list = (object) array('id' => '1',
            'form_id' => '6',
            '10091437300560754' => 'Ronaldo');

echo "<pre>";
print_r($list);
//then I tried to access:
echo $list->$fieldss['fields'];
Disha V.
  • 1,834
  • 1
  • 13
  • 21