Wednesday, 14 August 2013

php: how to pass current object to fuction?

php: how to pass current object to fuction?

$hookObj = t3lib_div::getUserObj($classRef);
if (method_exists($hookObj, $func)) {
$hookObj->$func($params, $this);
}
I saw above script pass $this to a function, so I am trying to figure out
how to pass $this to a function, I did below test:
<?php
class a {
public $var1 = 'var1';
public $var2 = 'var2';
}
$obj0 = new a;
class b {
function init($pObj){
var_dump($pObj->var1);
}
}
$obj1 = new b;
$obj1->init($obj0);
I can pass an object $obj0 to function, but how could I pass $this the
current object to fuction?

No comments:

Post a Comment