- Output for 5.3.0 - 5.3.28, 5.4.0 - 5.4.28
- Fatal error: Cannot use $this as lexical variable in /in/48HXU on line 13
Process exited with code 255.
<?php
//Simple math class
class Math
{
function __construct($a) {
$this->a =$a;
}
//Returns a closure
function mul()
{
//We can't directly use $this inside closure
$self = $this;
return function($n) use($this) {
return $n*$this->a;
};
}
}
$math = new Math(5);
$mul = $math->mul();
echo $mul(4); //Output : 20
?>