Adding anonymous function and call the public variable in an anonymous function by using magic function called __invoke();
<?php
// Your code here!
class model
{
public $greet;
public $a =”hello”;
function __construct()
{
$this->greet = function(){
echo $this->a;
};
}
}
$model = new model();
$model->greet->__invoke();
?>
Leave a comment