3v4l.org

run code in 300+ PHP versions simultaneously
<?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();
Output for 5.3.0 - 5.3.28, 5.4.0 - 5.4.29
Parse error: syntax error, unexpected ')' in /in/NhbvF on line 34
Process exited with code 255.

preferences:
195.24 ms | 1395 KiB | 66 Q