My favorites | Sign in
Logo
          
New issue | Search
for
| Advanced search | Search tips
Issue 115: jsonEncode throws warnings (and fills up error logs) when recursion is detected by server
2 people starred this issue and may be notified of changes. Back to list
Status:  Accepted
Owner:  ----
Type-Enhancement
Priority-Medium
Milestone-FirePHP...re-0.3.2


Sign in to add a comment
 
Reported by na...@naterkane.com, Jul 07, 2009
What steps will reproduce the problem?
1. install FirePHP
2. view your error log file

What is the expected output? What do you see instead?
I don't expect to see hundreds of errors getting logged with each pageview
of the software i'm testing.

ERROR - 2009-07-07 14:49:38 --> Severity: Warning  --> json_encode():
recursion detected /{path to libraries}/libraries/FirePHP.php 970

What version of the product are you using? On what operating system?
FirePHP 0.3.1 running on OSX 10.5.7 running apache 2.2.11 & php 5.2.8

Please provide any additional information below.

Since of course recursion is something that is expected, there's no point
in filling up logfiles (especially during development/testing) with
completely useless information. Here, my proposed workaround is simply to
reassign the error handler before calling the method that tosses the
warning, and then return the error handler to whatever it was before after
the offensive line is finished executing.

 /**
   * Encode an object into a JSON string
   * 
   * Uses PHP's jeson_encode() if available
   * 
   * @param object $Object The object to be encoded
   * @return string The JSON string
   */
  public function jsonEncode($Object, $skipObjectEncode=false)
  {
    if(!$skipObjectEncode) {
      $Object = $this->encodeObject($Object);
    }
    
    if(function_exists('json_encode')
       && $this->options['useNativeJsonEncode']!=false) {
	  set_error_handler(array('FirePHP','jsonEncode_handler'));
      $return = @json_encode($Object);
	  restore_error_handler();
    } else {
      $return = $this->json_encode($Object);
    }
	return $return;
  }
  
  /**
   * dummy error handler set to to obsorb any errors thrown by jsonEncode
   * @param object $errno
   * @param object $errstr
   */
  function jsonEncode_handler($errno, $errstr)
  {
  	// don't do anything
  }
Comment 2 by christ...@christophdorn.com, Jul 09, 2009
I like this work-around. Thanks for the idea!
Status: Accepted
Labels: -Type-Defect Type-Enhancement Milestone-FirePHPCore-0.3.2
Comment 4 by na...@naterkane.com, Jul 09, 2009
@christoph you're welcome, I came across it with another project about an month and a half ago (and wrote 
about it for more detail/backstory here http://www.naterkane.com/blog/completely-suppressing-errors-in-
php/ )
Sign in to add a comment

Hosted by Google Code