<?php
class TestClass{
private $name;
public function __construct($name){
$this->$name=$name;
}
public function changeName($name){
$this->name=$name;
}
public function displayName(){
echo $this->name;
}
}
$testCls= new TestClass('Dmitry Fucintv');
$testCls->changeName=function($name){
$this->name='Other name';
};
call_user_func($testCls->changeName, 'Some name');
$testCls->displayName();
Deprecated: Creation of dynamic property TestClass::$Dmitry Fucintv is deprecated in /in/evtgj on line 6
Deprecated: Creation of dynamic property TestClass::$changeName is deprecated in /in/evtgj on line 17
Fatal error: Uncaught Error: Using $this when not in object context in /in/evtgj:18
Stack trace:
#0 /in/evtgj(20): {closure}('Some name')
#1 {main}
thrown in /in/evtgj on line 18
Process exited with code 255.
Fatal error: Uncaught Error: Using $this when not in object context in /in/evtgj:18
Stack trace:
#0 /in/evtgj(20): {closure}('Some name')
#1 {main}
thrown in /in/evtgj on line 18
Process exited with code 255.
Fatal error: Using $this when not in object context in /in/evtgj on line 18
Process exited with code 255.
Output for 5.1.0 - 5.1.6, 5.2.0 - 5.2.17
Parse error: syntax error, unexpected T_FUNCTION in /in/evtgj on line 17
Process exited with code 255.
Output for 5.0.0 - 5.0.5
Parse error: parse error, unexpected T_FUNCTION in /in/evtgj on line 17
Process exited with code 255.
Output for 4.4.2 - 4.4.9
Parse error: syntax error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/evtgj on line 4
Process exited with code 255.
Parse error: parse error, unexpected T_STRING, expecting T_OLD_FUNCTION or T_FUNCTION or T_VAR or '}' in /in/evtgj on line 4
Process exited with code 255.
Output for 4.3.2 - 4.3.4
Parse error: parse error, expecting `T_OLD_FUNCTION' or `T_FUNCTION' or `T_VAR' or `'}'' in /in/evtgj on line 4
Process exited with code 255.