ThomasJSmart
Programmer
- Sep 16, 2002
- 634
What i am trying to do is the following:
i have a class A which instantiates another class then calls a function in that class with a param for the processing function.
This second class runs a complicated script that calls the passed processing function a few times.
the processing function in class A needs to store the result in a param in class A. once the function in class B is done, class A should continue and be able to access the result.
storing the var in the param is proving to be difficult though.
this doesnt work
returns the error:
Fatal error: Using $this when not in object context on line 19
This doesnt work
the echo in start() doesnt print out anything
making all the functions in class A static works in this example but breaks in the actual application because of A being extended from other classes (and i'd rather not have to make the whole tree static... )
am i missing something here or do i need to find a completely different way of achieving what i want?
Thomas
site | / blog |
i have a class A which instantiates another class then calls a function in that class with a param for the processing function.
This second class runs a complicated script that calls the passed processing function a few times.
the processing function in class A needs to store the result in a param in class A. once the function in class B is done, class A should continue and be able to access the result.
storing the var in the param is proving to be difficult though.
this doesnt work
Code:
class B{
public function do_something($something){
$data = 123;
call_user_func($something, $data);
}
}
class A{
public $result = 0;
public function start(){
$b = new B();
$b->do_something('A::process');
echo $this->result;
}
public function process($data){
$this->result = $data;
}
}
$a = new A();
$a->start();
returns the error:
Fatal error: Using $this when not in object context on line 19
This doesnt work
Code:
class B{
public function do_something($something){
$data = 123;
call_user_func($something, $data);
}
}
class A{
static public $result = 0;
public function start(){
$b = new B();
$b->do_something('A::process');
echo $this->result;
}
public function process($data){
A::$result = $data;
}
}
$a = new A();
$a->start();
the echo in start() doesnt print out anything
making all the functions in class A static works in this example but breaks in the actual application because of A being extended from other classes (and i'd rather not have to make the whole tree static... )
am i missing something here or do i need to find a completely different way of achieving what i want?
Thomas
site | / blog |