php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #45895 Exception in set_error_handler() messes up backtrace args
Submitted: 2008-08-22 21:52 UTC Modified: 2008-09-02 13:35 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:0 (0.0%)
From: jmcgraw1 at gmail dot com Assigned: dmitry
Status: Closed Package: Scripting Engine problem
PHP Version: 5.2.6 OS: CentOS
Private report: No CVE-ID:
 [2008-08-22 21:52 UTC] jmcgraw1 at gmail dot com
Description:
------------
Throwing an exception within set_error_handler() produces an exception which produces a messed up backtrace. Each entry within the backtrace contains the 'args' for the previous call, with the most immediate entry missing its 'args'. In the case of my example below the string 'foobar' should be in the array 'args' for the call to B(), not A().

Reproduce code:
---------------
function handle_errors() {
	throw new ErrorException();
}

set_error_handler('handle_errors', E_ALL);

function A() {
	$foo->bar; // Purposely cause error
}

function B($c) {
	A();
}

try {
	B('foobar');
} catch (Exception $e) {
	var_dump($e->getTrace());
}

Expected result:
----------------
array(3) {
  [0]=>
  array(4) {
    ["file"]=>
    string(42) "/home/public/pdt/framework/html/error.php"
    ["line"]=>
    int(10)
    ["function"]=>
    string(13) "handle_errors"
    ["args"]=>
    array(0) {
    }
  }
  [1]=>
  array(4) {
    ["file"]=>
    string(42) "/home/public/pdt/framework/html/error.php"
    ["line"]=>
    int(14)
    ["function"]=>
    string(1) "A"
  }
  [2]=>
  array(3) {
    ["file"]=>
    string(42) "/home/public/pdt/framework/html/error.php"
    ["line"]=>
    int(18)
    ["function"]=>
    string(1) "B"
    ["args"]=>
    array(1) {
      [0]=>
      string(6) "foobar"
    }
  }
}


Actual result:
--------------
array(3) {
  [0]=>
  array(4) {
    ["file"]=>
    string(42) "/home/public/pdt/framework/html/error.php"
    ["line"]=>
    int(10)
    ["function"]=>
    string(13) "handle_errors"
    ["args"]=>
    array(0) {
    }
  }
  [1]=>
  array(4) {
    ["file"]=>
    string(42) "/home/public/pdt/framework/html/error.php"
    ["line"]=>
    int(14)
    ["function"]=>
    string(1) "A"
    ["args"]=>
    array(1) {
      [0]=>
      string(6) "foobar"
    }
  }
  [2]=>
  array(3) {
    ["file"]=>
    string(42) "/home/public/pdt/framework/html/error.php"
    ["line"]=>
    int(18)
    ["function"]=>
    string(1) "B"
  }
}


Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2008-08-27 13:13 UTC] jmcgraw1 at gmail dot com
PHP 5.2.6 (cli) (built: May  8 2008 16:50:48)

Output:
array(3) {
  [0]=>
  array(4) {
    ["file"]=>
    string(26) "/home/jmcgraw/test_old.php"
    ["line"]=>
    int(10)
    ["function"]=>
    string(13) "handle_errors"
    ["args"]=>
    array(0) {
    }
  }
  [1]=>
  array(4) {
    ["file"]=>
    string(26) "/home/jmcgraw/test_old.php"
    ["line"]=>
    int(14)
    ["function"]=>
    string(1) "A"
    ["args"]=>
    array(1) {
      [0]=>
      string(6) "foobar"
    }
  }
  [2]=>
  array(3) {
    ["file"]=>
    string(26) "/home/jmcgraw/test_old.php"
    ["line"]=>
    int(18)
    ["function"]=>
    string(1) "B"
  }
}

PHP 5.2.7-dev (cli) (built: Aug 27 2008 12:47:06)

Output:
array(3) {
  [0]=>
  array(4) {
    ["file"]=>
    string(22) "/home/jmcgraw/test_new.php"
    ["line"]=>
    int(10)
    ["function"]=>
    string(13) "handle_errors"
    ["args"]=>
    array(0) {
    }
  }
  [1]=>
  array(4) {
    ["file"]=>
    string(22) "/home/jmcgraw/test_new.php"
    ["line"]=>
    int(14)
    ["function"]=>
    string(1) "A"
    ["args"]=>
    array(1) {
      [0]=>
      string(6) "foobar"
    }
  }
  [2]=>
  array(3) {
    ["file"]=>
    string(22) "/home/jmcgraw/test_new.php"
    ["line"]=>
    int(18)
    ["function"]=>
    string(1) "B"
  }
}

Result:
Latest snapshot does NOT solve problem.
 [2008-09-02 13:35 UTC] dmitry@php.net
The bug is already fixed in CVS HEAD and PHP_5_3, however it is not possible to fix it in PHP_5_2 branch without binary compatibility break.
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Sun Apr 20 15:01:54 2014 UTC