Hi,
I am new to php progamming and having problems with functions passing to class's and I think its a scope problem.
Free free to critque my code at will as i want to learn.
What I am doing is calling a debug class that writes to a debug.txt output file, and I have to declare the variable as a global in each function, can I use a superglobal variable so it knows that it is a debug class without havinng to re-declare it in every function in php? here is a sample of the code and the class
include("c:\\debug.php");
$d = new debug;
//if I set global $d here and do not set global $d in
//any function it fails with the error message "Fatal error: Call
//to a member function on a non-object", this does make sense
//to me as how can the function ever know the object,
//so is there a way to declare global $d so its like a super global?
function newbie() {
//this works...
global $d
$d->s("function newbie");
$var1 = "hello";
$d->s("v = " . $var1);
$d->s("end function newbie");
}
function beginner() {
//this works...
global $d
$d->s("function beginner");
$var2 = "world";
$d->s("v = " . $var2);
$d->s("end function beginner")
}
//debug.php
//The Class- this all works and really isnt the issue with the class
class debug {
function debug() {
...create the file, open for writing etc etc
}
function s($debug) {
...writes what ever is passed to it...
}
}
These two files are the only two used as this is just a tutorial for me to learn php so there is no sessions etc set up, any help goes beyond thankyou as i am stumped as to what/which way to go, I had a look at serilise/unserilise but this seems really clumsy or am I missing something here, thanks guys.
BBK