I'm having a problem calling a method from within a function. Here is some simplified code that recreates the problem:
<?
class base {
var $error;
function base() {
$this->error = FALSE;
}
function error( $message ) {
$this->error = TRUE;
echo "There was an error: $message";
}
}
$base = new base;
$base->error( "This does not cause an error");
function test() {
$msg = "<b>Fatal Error:</b> Call to a member function on a non-object in following line";
$base->error( $msg );
}
test();
?>
Above I am declaring a class, instantiating it, and trying to access one of the methods from within a function. This results in the error message: "Call to a member function on a non-object". I CAN use the method outside of the function without a problem.
It DOES work if the line,
$obj_in_function = new base;
is inserted inside the function test(), so I know this is a scope issue, but I'm confused. Isn't the whole point of having a class is so I can reuse the methods as I need to?
I'm guessing I'm missing something simple here!