Imaginary Error (PHP bug?)

Reply

Join Date: Dec 2008
Posts: 20
Reputation: cloudedvision is an unknown quantity at this point 
Solved Threads: 0
cloudedvision cloudedvision is offline Offline
Newbie Poster

Imaginary Error (PHP bug?)

 
0
  #1
Apr 28th, 2009
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:

  1. $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:

  1. 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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,440
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 135
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: Imaginary Error (PHP bug?)

 
0
  #2
Apr 28th, 2009
  1. $this->error->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
Isn't that code meant to be the following:
  1. $this->$error->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
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.
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Imaginary Error (PHP bug?)

 
0
  #3
Apr 29th, 2009
Originally Posted by cwarn23 View Post
Isn't that code meant to be the following:
  1. $this->$error->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
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.
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.
Last edited by kkeith29; Apr 29th, 2009 at 12:12 am.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,440
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 135
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: Imaginary Error (PHP bug?)

 
0
  #4
Apr 29th, 2009
Originally Posted by kkeith29 View Post
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.
From what I have learnt in oop php-gtk, variables are the containers and in that code it appears to the left is the parrent - in the middle is the container and to the right is the method. If however you are trying to call two methods at the same time then that will never work and needs to be set on two lines with another container. So the previous post of mine was assuming $error was a container. If that is not the case and 'error' is a method then the following is what you may need to do:
  1. $container=$this->error;
  2. $container->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
  3. //or
  4. $container=$this->error();
  5. $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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Imaginary Error (PHP bug?)

 
0
  #5
Apr 29th, 2009
Where did it say he's using php-gtk?

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.
Reply With Quote Quick reply to this message  
Join Date: Sep 2007
Posts: 1,440
Reputation: cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about cwarn23 has a spectacular aura about 
Solved Threads: 135
cwarn23's Avatar
cwarn23 cwarn23 is offline Offline
Nearly a Posting Virtuoso

Re: Imaginary Error (PHP bug?)

 
0
  #6
Apr 29th, 2009
Originally Posted by kkeith29 View Post
Where did it say he's using php-gtk?
I didn't say he is using php-gtk but I said from my experience of php-gtk which is just like php.

Originally Posted by kkeith29 View Post
He is just referencing another class through the error variable.
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.

Originally Posted by kkeith29 View Post
You also can call two methods at once with oop. All you have to do is return $this in the function.
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.
  1. $tester=$this->error;
  2. $tester->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
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.
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
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: Imaginary Error (PHP bug?)

 
0
  #7
Apr 29th, 2009
Originally Posted by cwarn23 View Post
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.
  1. $tester=$this->error;
  2. $tester->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404');
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.
Dynamic variables work differently in oop. Putting a $ in front of the variable doesn't work.
ex.
  1. $this->$error->trigger('blah');
is run as
  1. $this->->trigger('blah');
if $error is not defined outside the class.

You do not need a $ to reference variables inside a class. I think I am misunderstanding your take on this.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 20
Reputation: cloudedvision is an unknown quantity at this point 
Solved Threads: 0
cloudedvision cloudedvision is offline Offline
Newbie Poster

Re: Imaginary Error (PHP bug?)

 
0
  #8
Apr 29th, 2009
Dynamic variables are irrelevant to my problem.

Here's where I set $this->error (To clear up any misunderstanding)

  1. $this->load('classes/errorHandler');
  2. $this->error = new errorHandler($mode, &$this->errorLog);

Heres where the problem is happening

  1. //Now lets process the URL with routes
  2. $this->load('classes/route');
  3. $this->routeHandler = new routeHandler($this->mode, 'config/routes.php');
  4. if(!($this->routeVars = $this->routeHandler->checkRoutes($url))) //Usually does not return false, so the error is not triggered, but still causes problems.
  5. $this->error->trigger('noRoute','URL Has No Matching Route',array('URL'=>$url),'404'); //Debugger stops here
  6. $this->debug->log('Route processed');

Here's the error class:

  1. class errorHandler {
  2. function __construct($cli, $errorLog) {
  3. $this->path = 'app/errors/';
  4. if($cli==TAM_CLI)
  5. $this->path .= 'cli';
  6. else
  7. $this->path .= 'web';
  8. $this->path .= '/';
  9. $this->errorLog = &$errorLog;
  10. }
  11.  
  12. function trigger($id, $title, $details = array(), $http) {
  13. $this->id = $id;
  14. $this->details = $details;
  15. if($http=='404')
  16. header('HTTP/1.0 404 Not Found');
  17. require($this->path.'template.php');
  18. $error = 'Tamarin encountered error '.$id.'. Associated details:';
  19. foreach($details as $key => $value)
  20. $error .= '[ '.$key.' => "'.$value.'" ]';
  21. $this->errorLog->log($error);
  22. exit; //Comment this out and the debugger works fine.... until another unexecuted exit or die() statement is stumbled upon.
  23. }
  24.  
  25. function display() {
  26. require($this->path.$this->id.'.php');
  27. }
  28. };

Here's the log class (Which is the class of both $this->debug and $this->errorLog)

  1. <?php
  2.  
  3. class log {
  4. function __construct($args) {
  5. //Default values
  6. if(!isset($args['passive']))
  7. $args['passive'] = true;
  8. if(!isset($args['mode']))
  9. $args['mode'] = 'a';
  10.  
  11. //Set arguments
  12. $this->fn = $args['fn'];
  13. $this->passive = $args['passive'];
  14. $this->mode = $args['mode'];
  15.  
  16. //If passive, don't open the file until log();
  17. if($this->passive)
  18. $this->handler = false;
  19. else
  20. $this->open();
  21. }
  22.  
  23. //Open the file
  24. function open() {
  25. $this->handler = fopen($this->fn,$this->mode);
  26. }
  27.  
  28. //Close the file
  29. function close() {
  30. fclose($this->handler);
  31. $this->handler = false;
  32. }
  33.  
  34. //Log an entry
  35. function log($msg) {
  36. if($this->passive) //If passive, open up the file handler
  37. $this->open();
  38.  
  39. fwrite($this->handler,time().' '.$msg.NL); //Log the error
  40.  
  41. if($this->passive) //If passive, close the file handler
  42. $this->close();
  43. }
  44.  
  45. function __destruct() {
  46. if($this->handler) //If handler is open, close it
  47. $this->close();
  48. }
  49. };
  50.  
  51. class blankLog {
  52. function log($msg) {}
  53. };
  54.  
  55. ?>
Last edited by cloudedvision; Apr 29th, 2009 at 6:18 pm.
Reply With Quote Quick reply to this message  
Join Date: Apr 2005
Posts: 1,402
Reputation: ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light ShawnCplus is a glorious beacon of light 
Solved Threads: 225
Sponsor
ShawnCplus's Avatar
ShawnCplus ShawnCplus is offline Offline
Code Monkey

Re: Imaginary Error (PHP bug?)

 
0
  #9
Apr 29th, 2009
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.,
  1. class Log
  2. {
  3. /**
  4.   * File handle for the log
  5.   * @var Resource
  6.   */
  7. 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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 20
Reputation: cloudedvision is an unknown quantity at this point 
Solved Threads: 0
cloudedvision cloudedvision is offline Offline
Newbie Poster

Re: Imaginary Error (PHP bug?)

 
0
  #10
Apr 29th, 2009
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.)
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC