View Single Post
Old 09-10-2010, 10:39 PM  
qw12er
Confirmed User
 
Join Date: Apr 2004
Location: Montreal
Posts: 799
PHP Guru -- here's a tough one!

1) Why can't I use '$this' since when $func() is executed it will be in foo's object context ? (So $this should be available ?!)
2) How can I avoid this problem ? (cause I really need to call a function from class foo)


Quote:
class foo{

public function internal(){
print 'Hello world.';
}

public function __call($method, $args){
if(isset($this->$method)){
$func = $this->$method;
$func();
}
}
}

$f = new foo();
$f->bar = function () {$this->internal();};
$f->bar();
__________________
I have nothing to advertise ... yet.
qw12er is offline   Share thread on Digg Share thread on Twitter Share thread on Reddit Share thread on Facebook Reply With Quote