| | |
Imaginary Error (PHP bug?)
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Dec 2008
Posts: 20
Reputation:
Solved Threads: 0
I call this an imaginary error, because the code that causes is never run, and it does not report an error, but the functionality breaks.
I'm developing a PHP framework. I have a debugger that writes lines to the a file throughout the execution of the framework. I noticed today that the debugger was cutting off midway through, and didn't start until the very end. (And fwrite was returning the normal int throughout) So I did my usual debugging course, and found the line of code that was causing it. It was this:
The odd thing about this was that it was not being executed, yet still causing the debugger to stop. It was within an if statement that in most circumstances would not return true. I looked into the trigger() function, and found the code causing the error:
Yep, thats what was causing the problem. Although that particular line of code was not being executed, it was still halting the debugger. (die() yielded the same results) I commented that line, and other various exit; statements throughout the framework did the same thing.
This is the weirdest bug I have ever encountered. Is there a way to fix this? Is this a known bug?
I'm developing a PHP framework. I have a debugger that writes lines to the a file throughout the execution of the framework. I noticed today that the debugger was cutting off midway through, and didn't start until the very end. (And fwrite was returning the normal int throughout) So I did my usual debugging course, and found the line of code that was causing it. It was this:
php Syntax (Toggle Plain Text)
$this->error->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
The odd thing about this was that it was not being executed, yet still causing the debugger to stop. It was within an if statement that in most circumstances would not return true. I looked into the trigger() function, and found the code causing the error:
php Syntax (Toggle Plain Text)
exit;
Yep, thats what was causing the problem. Although that particular line of code was not being executed, it was still halting the debugger. (die() yielded the same results) I commented that line, and other various exit; statements throughout the framework did the same thing.
This is the weirdest bug I have ever encountered. Is there a way to fix this? Is this a known bug?
Last edited by cloudedvision; Apr 28th, 2009 at 10:48 pm.
•
•
•
•
php Syntax (Toggle Plain Text)
$this->error->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
php Syntax (Toggle Plain Text)
$this->$error->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
•
•
•
•
Isn't that code meant to be the following:
The code above will only work if $error is a method of $this and trigger() is a method of $error. Also you forgot a dollar sign for the middle variable.php Syntax (Toggle Plain Text)
$this->$error->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
Also, can you post your code cloudedvision? That way we can help debug it better.
Lately I have been building my personal php framework and have a error logger like yours. It shouldn't be hard to find the problem.
Last edited by kkeith29; Apr 29th, 2009 at 12:12 am.
•
•
•
•
Why does he need a dollar sign? I don't think he wants it to be a dynamic call.
Also, can you post your code cloudedvision? That way we can help debug it better.
Lately I have been building my personal php framework and have a error logger like yours. It shouldn't be hard to find the problem.
php Syntax (Toggle Plain Text)
$container=$this->error; $container->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404'); //or $container=$this->error(); $container->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
I didn't say he is using php-gtk but I said from my experience of php-gtk which is just like php.
If error is a variable then the error variable will need the $ sign before it. Note that dynamic variables have $$ before the name of the variable.
Although that is usually true there are some cases where that is not possible. I forget the reason but it only happens with certain objects.
-------
Also with the additional info kkeith29 has posted, perhaps the following code would be more relevant to test the problem.
If line one of the above code reports the error then you know that the error variable needs to be defined properly. If however it is the second line of the above code that reports the error then it is the trigger method that needs adjusting.
•
•
•
•
He is just referencing another class through the error variable.
•
•
•
•
You also can call two methods at once with oop. All you have to do is return $this in the function.
-------
Also with the additional info kkeith29 has posted, perhaps the following code would be more relevant to test the problem.
php Syntax (Toggle Plain Text)
$tester=$this->error; $tester->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
Try not to bump 10 year old threads as it can be really annoying.
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
Like php then read my website at http://syntax.cwarn23.net/
Star-Trek-Atlantis - now that's what I call a movie ^_^
My favourite PC. - MacGyver Fan
Bad english note: dis-iz-2b4u
•
•
•
•
I didn't say he is using php-gtk but I said from my experience of php-gtk which is just like php.
If error is a variable then the error variable will need the $ sign before it. Note that dynamic variables have $$ before the name of the variable.
Although that is usually true there are some cases where that is not possible. I forget the reason but it only happens with certain objects.
-------
Also with the additional info kkeith29 has posted, perhaps the following code would be more relevant to test the problem.
If line one of the above code reports the error then you know that the error variable needs to be defined properly. If however it is the second line of the above code that reports the error then it is the trigger method that needs adjusting.php Syntax (Toggle Plain Text)
$tester=$this->error; $tester->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
ex.
PHP Syntax (Toggle Plain Text)
$this->$error->trigger('blah');
PHP Syntax (Toggle Plain Text)
$this->->trigger('blah');
You do not need a $ to reference variables inside a class. I think I am misunderstanding your take on this.
•
•
Join Date: Dec 2008
Posts: 20
Reputation:
Solved Threads: 0
Dynamic variables are irrelevant to my problem.
Here's where I set $this->error (To clear up any misunderstanding)
Heres where the problem is happening
Here's the error class:
Here's the log class (Which is the class of both $this->debug and $this->errorLog)
Here's where I set $this->error (To clear up any misunderstanding)
php Syntax (Toggle Plain Text)
$this->load('classes/errorHandler'); $this->error = new errorHandler($mode, &$this->errorLog);
Heres where the problem is happening
php Syntax (Toggle Plain Text)
//Now lets process the URL with routes $this->load('classes/route'); $this->routeHandler = new routeHandler($this->mode, 'config/routes.php'); if(!($this->routeVars = $this->routeHandler->checkRoutes($url))) //Usually does not return false, so the error is not triggered, but still causes problems. $this->error->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404'); //Debugger stops here $this->debug->log('Route processed');
Here's the error class:
php Syntax (Toggle Plain Text)
class errorHandler { function __construct($cli, $errorLog) { $this->path = 'app/errors/'; if($cli==TAM_CLI) $this->path .= 'cli'; else $this->path .= 'web'; $this->path .= '/'; $this->errorLog = &$errorLog; } function trigger($id, $title, $details = array(), $http) { $this->id = $id; $this->details = $details; if($http=='404') header('HTTP/1.0 404 Not Found'); require($this->path.'template.php'); $error = 'Tamarin encountered error '.$id.'. Associated details:'; foreach($details as $key => $value) $error .= '[ '.$key.' => "'.$value.'" ]'; $this->errorLog->log($error); exit; //Comment this out and the debugger works fine.... until another unexecuted exit or die() statement is stumbled upon. } function display() { require($this->path.$this->id.'.php'); } };
Here's the log class (Which is the class of both $this->debug and $this->errorLog)
php Syntax (Toggle Plain Text)
<?php class log { function __construct($args) { //Default values if(!isset($args['passive'])) $args['passive'] = true; if(!isset($args['mode'])) $args['mode'] = 'a'; //Set arguments $this->fn = $args['fn']; $this->passive = $args['passive']; $this->mode = $args['mode']; //If passive, don't open the file until log(); if($this->passive) $this->handler = false; else $this->open(); } //Open the file function open() { $this->handler = fopen($this->fn,$this->mode); } //Close the file function close() { fclose($this->handler); $this->handler = false; } //Log an entry function log($msg) { if($this->passive) //If passive, open up the file handler $this->open(); fwrite($this->handler,time().' '.$msg.NL); //Log the error if($this->passive) //If passive, close the file handler $this->close(); } function __destruct() { if($this->handler) //If handler is open, close it $this->close(); } }; class blankLog { function log($msg) {} }; ?>
Last edited by cloudedvision; Apr 29th, 2009 at 6:18 pm.
If it's just dying with no message you might want to check to see if you have your error_reporting ini value set to something other than E_ALL (development only, don't turn this on live). Also, consider using braces around your conditions even if it's only one statement. It disambiguates the statements and is less confusing. I can't tell you how many times I've forgot the braces then added another statement and wondered why it didn't execute.
Also, your classes are dynamically instantiating members you should probably define them before-hand to make things easier, ie.,
Also, your classes are dynamically instantiating members you should probably define them before-hand to make things easier, ie.,
PHP Syntax (Toggle Plain Text)
class Log { /** * File handle for the log * @var Resource */ private $handler = NULL;
Last edited by ShawnCplus; Apr 29th, 2009 at 6:52 pm.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
•
•
Join Date: Dec 2008
Posts: 20
Reputation:
Solved Threads: 0
Its definitely E_ALL, my framework automatically sets it to that in development mode. fwrite returns an integer, not false, so there is no error there. (But for some reason it doesn't work)
I've heard the tip about using brackets always, but I've never have bothered because I don't forget to add brackets when I add another statement. (Which is weird, I always end up forgetting to close up multiple parenthesis, add periods to connect strings and variables, etc.)
I've heard the tip about using brackets always, but I've never have bothered because I don't forget to add brackets when I add another statement. (Which is weird, I always end up forgetting to close up multiple parenthesis, add periods to connect strings and variables, etc.)
![]() |
Similar Threads
- Help with automatic update problem and more (Viruses, Spyware and other Nasties)
Other Threads in the PHP Forum
- Previous Thread: How to pass values from nonpc games to webservers
- Next Thread: file upload wont work!
| Thread Tools | Search this Thread |
.htaccess alerts apache api archive array autocomplete beginner binary broken cakephp checkbox class cms code convert cron curl database dataentry date display duplicates dynamic echo email emptydisplayvalue error execute explodefunction file files firstoptioninphpdroplist folder form forms function functions google hack href htaccess html htmlspecialchars image include insert ip javasciptvalidation javascript joomla keywords limit link login mail matching menu methods mlm multiple mysql network object oop paypal pdf php problem query radio random recursion recursive redirect remote script search securephp server sessions shot sms source space sql subscription syntax system table tutorial tutorials update upload url validator variable video web youtube






