Hi all,
I am a serious glutton for this error : "Call to a member function on a non-object"…
I have created a debug class to output a debug.txt file for debugging purposes and was getting this error and thanks to you guys I finally found out that I needed to declare the object as global in every single function as I was trying to make a superglobal or superclass type construct so that I could always refer to my debug object from anywhere.
Well this saga gets a little stranger, I am now using the php function "set_error_handler" and have come across the same type of problem but it is when i declare the class itself within the function versus declaring the class outside of the function,
include("c:\\Debug.php");
set_error_handler("cust_err_hand");
//do something flakey to cause a error like
$string = "newbie";
join('', $string);
//This fails....
function cust_err_hand($type, $msg, $file, $line) {
$x = new Debug;
global $x;
$x->s("function cust_err_hand");
$x->s("Type : $type");
.......etc...etc....
}
//This works....
$x = new Debug;
function cust_err_hand($type, $msg, $file, $line) {
global $x;
$x->s("function cust_err_hand");
$x->s("Type : $type");
.......etc...etc....
}
The only difference is the declaring of the class outside/inside a function.
The debug class is in another php file from this one that is calling it.
Is this a case of object persistence? Like does the object declared outside the function persist and when created inside the function have a destructer or destroy type behavior?
Thanks again guys
BBK
😃