I received the following error :
Closure Object ( [this] => test1 Object ( ) [parameter] => Array ( [$handler] => ) )
I have no idea what it means, I am trying out new things with php. My purpose is to call an anonymous function to execute a list of commands on the fly, for the purpose of learning php call backs and closures i created 3 classes.
test1, test2 extends hand
<?php
// test1.php
class test1
{
public function __construct() {
}
function dataTable() {
test2::table("food", function(hand $handler){
$handler->put("cookies");
});
}
}
// test2.php
class test2 extends hand
{
public function __construct() {
echo $this->info;
}
static function table($s, $b) {
echo "called from Test2, Table 1st parameter ";
echo $s ." <br><br>  ";
echo "called from Tes2, table 2nd parameter ";
print_r($b);
echo "---end";
}
}
// hand.php
class hand
{
protected $info;
public function __construct() {
print_r($this->info);
}
function put($b) {
$this->info = $b;
}
}
I want to retrieve the result entered here $handler->put("cookies");
from within the hand class and test2 class, the first parameter works as expected but i received an unfamiliar php error with the second parameter.
Please help, what am i doing wrong or aren't doing? i am trying to understand the callback and closures