In the code sample below, how do I access the value of $this inside the callback function in the hello() method? I also attached the class to this post if you want to execute it. I am getting the error: Fatal error: Using $this when not in object context I want $this to point to the current instance.
class Person {public function hello() { $list = array(1, 2, 3, 4, 5); $this->iterate($list, function($num) { echo $this->multiply_by_100($num) . 'hello <br>'; });}public function iterate($list, $callback) { foreach ($list as $num) { call_user_func($callback, $num); }}public function multiply_by_100($num) { return $num * 100;}} $d = new Person();$d->hello();
php_closure.php