Hello,
As my username denotes, I’m new to OOP concepts in PHP. I was reading an article recently about helper functions. As a skill development exercise, I’m creating a class that will contain several helper functions. My first method will assist with debugging code. I use this sometimes when I’m debugging code:
print "<pre>";
print_r($var);
print "</pre>";
So far, my class method solution looks like this:
class Helpers {
private static $devStatus = 1; //0 for off 1 for on
public static function devDump($blurb=null, $var) {
// Check to see if we are in debug mode
if (isset(self::$devStatus) && self::$devStatus==1) {
print $blurb.": ";
print "<pre>";
print_r($var);
print "</pre>";
}
}
}
Here’s how I use the above code:
$someArray = array("firstname"=>"Site", "lastname"=>"Point");
Helpers::devDump('$someArray', $someArray);
The output looks like this:
$someArray:
Array
(
[firstname] => Site
[lastname] => Point
)
My question is…Is this how you would do it? Any suggested improvements?
The only thing I tried to do, but couldn’t, is have the method print out the variable name being passed as the $var parameter. From what I tried and what I read with a Google search, PHP can’t do this yet. Is this true? In all of my Noob glory did I miss something? My primitive solution, in the code above, is to pass in the name of the variable as the first parameter and the value of the variable as the second parameter.
Is it ok to print text to the screen in the middle of a class like that?
Thanks,
OOPNoob