RosettaCodeData/Task/Add-a-variable-to-a-class-instance-at-runtime/PHP/add-a-variable-to-a-class-instance-at-runtime.php

10 lines
141 B
PHP
Raw Permalink Normal View History

2013-04-10 14:58:50 -07:00
class E {};
$e=new E();
$e->foo=1;
$e->{"foo"} = 1; // using a runtime name
$x = "foo";
$e->$x = 1; // using a runtime name in a variable