tomcatexodus
Jun 15th, 2010, 11:33 PM
I'm having an issue with callback functions, specifically storing them...
If I have a class:
class myObject{
protected $callback;
public function __construct($callbackFunction){
$this->callback = $callbackFunction;
.
.
.
}
public function doSomething($args){
if(is_callable($this->callback)){
return $this->callback($args);
}
}
}
And I try doing this:
function foo($arg){
return strtoupper($arg);
}
$myNewObject = new myObject("foo");
echo $myNewObject->doSomething("bar"); //should echo BAR
I end up with an error:
Fatal Error: Call to undefined method MyObject::callback() in ...
The is_callable() is succeeding, but the actual callback function call is the line failing with that error.
This isn't exactly what I'm doing obviously, but its a replicate of the code. Any ideas?
If I have a class:
class myObject{
protected $callback;
public function __construct($callbackFunction){
$this->callback = $callbackFunction;
.
.
.
}
public function doSomething($args){
if(is_callable($this->callback)){
return $this->callback($args);
}
}
}
And I try doing this:
function foo($arg){
return strtoupper($arg);
}
$myNewObject = new myObject("foo");
echo $myNewObject->doSomething("bar"); //should echo BAR
I end up with an error:
Fatal Error: Call to undefined method MyObject::callback() in ...
The is_callable() is succeeding, but the actual callback function call is the line failing with that error.
This isn't exactly what I'm doing obviously, but its a replicate of the code. Any ideas?