What is the difference between these codes in PHP?
code1:
$func=function($name){
return "name : ".$name;
};
echo $func('john');// << it is true
code2:
class myclass{
public $name;
public $func;
}
$c=new myclass();
$c->func=function($n){
return "name : ".$n;
};
echo $c->func();// << ?!.. is error
The first code is working properly but the second code gives an error. How can I fix it?
Sidenote: My PHP version is 5.3.4