3v4l.org

run code in 300+ PHP versions simultaneously
e<?php class foo { public $aVariableName = 'aValue'; function __construct() { $this->a = "hello"; $this->b = "hi"; $this->val = "howdy"; $val = "a"; echo $this->{$val}; // outputs "hello" echo "\n"; $val = "b"; echo $this->{$val}; // outputs "hi" echo "\n"; echo $this->val; //outputs "howdy" echo "\n"; echo $this->{"val"}; $this->setConfigParam('aVariableName', array('one', 'two', 'three')); // echo $this->$aVariableName; $name = 'aVariableName'; echo "\n"; var_dump($this->$name); echo "\n"; var_dump($this->_aConfigParams); } public function setConfigParam( $sName, $sValue ) { if ( isset( $this->$sName ) ) { $this->$sName = $sValue; } else { $this->_aConfigParams[$sName] = $sValue; } } } $foo = new foo();

preferences:
38.29 ms | 402 KiB | 5 Q