Strange class variable (not php5 related)<

liunx

Guest
<?php
class System {
var $start_time;
var $end_time;
var $page_time;
var $debug_on;
var $debug_content;
var $debug_write;

var $sql_result;
var $sql_queries;
var $sql_error;
var $sql_totsec;

function System(){
#
# Assign start vars
#
$this->start_time = microtime();
$this->debug = $this->debug('start');
$this->debug_write = true;
$this->sql_queries = 0;
$this->sql_totsec = 0;
$this->debug_on = false;
$this->debug_write = true;

#
# Turn on ooutput buffering
#
ob_start();
}

function debug($act,$cont=''){
#
# different debug actions
#
if($act == 'start'){
#
# Make sure debug is not already on
#
if($this->debug_on == false){
$this->debug_on = true;
$this->debug('cont',$this->lang(4));
}
else
{
$this->debug('cont',$this->lang(5));
}
}

if($act == 'cont'){
#
# Make sure debug has arleady started, if not start it.
#
if($this->debug_on == true){
$this->debug_content .= $cont."\n";
}
else
{
$this->debug('start');
$this->debug('cont',$this->lang(6));
}
}

if($act == 'stop'){
#
# Write debug to file & close it
#

#
# I echo out $this->debug_on, and it should output 1(or true) but instead its empty therefore the if statement beneath it is false, and there won't anything written to the log file.
#
echo $this->debug_on;

if($this->debug_on == true){
if($this->debug_write == true){
if(!empty($this->debug_content)){
$this->debug('cont',$this->lang(2));

$this->debug_content .= "\n";

$this->debug_on = false;

$fp = fopen('logs/debug_log.txt','a');
fwrite($fp,$this->debug_content);
}
else
{
$this->debug('cont',$this->lang(1));
}
}
}
else
{
$this->debug('start');
$this->debug('cont',$this->lang(3));
}
}
}

function lang($id){
#
# Setup the lang array here
#
$lang = array(
1=>'debug(): stopped debug with no debug_content',
2=>'debug(): stopped debug',
3=>'debug(): attempted to stop debug, but debug was not open',
4=>'debug(): started debug',
5=>'debug(): attempted to start debug, but debug was already open',
6=>'debug(): attempted to write debug, but was not open. opened debug',

10=>'finish(): finished handling the page, closing up',

20=> 'sql_query(): executed succesfull query',
21=>'sql_query(): executed failed query: '.$this->sql_error,
22=>'sql_fetch(): returned succesfull',
23=>'sql_numrows(): returned succesfull',
24=>'Total sql execution time '.$this->page_time.' microseconds',

'no_id'=>'Requested unnown lang id');

if(!empty($lang[$id])){
return $lang[$id];
}
else
{
return $this->lang('no_id');
}
}

function finish(){
$this->end_time = microtime();
$this->page_time = $this->load_time($this->start_time,$this->end_time);

$this->debug('cont',$this->lang(24));

#
# Stop debug
#
$this->debug('stop');

#
# output internal buffer
#
ob_end_flush();
}
}

#
# This will start debug and set $system->debug_on = true
#
$system = new System;

#
# This will write the $system->debug_content to a file, and set $system->debug_on = false
#
$system->finish();
?>


as you can see i call the finish() function at the bottom. the finish function calls the debug('close') function. look at that and it's comment.

if you looked at the comment., i cnA'T FIND OUT WHY THAT VARIABLE IS EMPTY.

thanks in advance :Dthis

if($this->debug_on == false){

will not be true, ever. when you set something to true or false it is really being turned to 1 or 0, not false or true. they will be boolean, not a stringcouldn't you do this though?
if($this->debug_on === false){damn just when you think you're getting good at it ;) thanksOriginally posted by Josh
couldn't you do this though?
if($this->debug_on === false){
yesm tha tis the proper way to do it. so eiher way is fine. just not ==
 
Back
Top