Remove $errcontext argument to error handlers

I'm removing the argument entirely here, but we might want to change
this to passing null or and empty array instead, if the impact of
dropping it entirely turns out to be too large.

This was deprecated as part of https://wiki.php.net/rfc/deprecations_php_7_2
as a doc-only deprecation.
This commit is contained in:
Nikita Popov 2019-01-30 15:54:35 +01:00
parent 790798f61e
commit 2f1f34952e
47 changed files with 49 additions and 59 deletions

View file

@ -34,6 +34,7 @@ PHP 8.0 UPGRADE NOTES
interpreted as strings.
. Removed ability to specify an autoloader using an __autoload() function.
spl_autoload_register() should be used instead.
. Removed the $errcontext argument for custom error handlers.
. Removed create_function(). Anonymous functions may be used instead.
. Removed each(). foreach or ArrayIterator should be used instead.
. Removed ability to unbind $this from closures that were created from a

View file

@ -2,7 +2,7 @@
Bug #29890 (crash if error handler fails)
--FILE--
<?php
function customErrorHandler($fErrNo,$fErrStr,$fErrFile,$fErrLine,$fClass) {
function customErrorHandler($fErrNo,$fErrStr,$fErrFile,$fErrLine) {
echo "error :".$fErrStr."\n";
}

View file

@ -2,7 +2,7 @@
Bug #29896 (Backtrace argument list out of sync)
--FILE--
<?php
function userErrorHandler($num, $msg, $file, $line, $vars)
function userErrorHandler($num, $msg, $file, $line)
{
debug_print_backtrace();
}
@ -22,6 +22,6 @@ function GenerateError2($A1)
GenerateError2("Test2");
?>
--EXPECTF--
#0 userErrorHandler(8, Undefined variable: b, %sbug29896.php, 11, Array ([A1] => Test1)) called at [%sbug29896.php:11]
#0 userErrorHandler(8, Undefined variable: b, %sbug29896.php, 11) called at [%sbug29896.php:11]
#1 GenerateError1(Test1) called at [%sbug29896.php:16]
#2 GenerateError2(Test2) called at [%sbug29896.php:19]

View file

@ -13,7 +13,7 @@ try {
} catch(Exception $e) {
echo "This Exception should be caught\n";
}
function errorHandler($errno, $errstr, $errfile, $errline, $vars) {
function errorHandler($errno, $errstr, $errfile, $errline) {
throw new Exception('Some Exception');
}
?>

View file

@ -41,6 +41,6 @@ echo "Done\n";
--EXPECTF--
Fatal error: Uncaught ErrorException: Undefined variable: id in %s:%d
Stack trace:
#0 %s(%d): env::errorHandler(8, '%s', '%s', 34, Array)
#0 %s(%d): env::errorHandler(8, '%s', '%s', 34)
#1 {main}
thrown in %s on line %d

View file

@ -38,7 +38,7 @@ $o->bar();
--EXPECTF--
Fatal error: Uncaught RuntimeException in %sbug45805.php:%d
Stack trace:
#0 %sbug45805.php(%d): PHPUnit_Util_ErrorHandler::handleError(8, 'Only variables ...', '%s', %d, Array)
#0 %sbug45805.php(%d): PHPUnit_Util_ErrorHandler::handleError(8, 'Only variables ...', '%s', %d)
#1 [internal function]: B->foo()
#2 %sbug45805.php(%d): ReflectionMethod->invoke(Object(B))
#3 %sbug45805.php(%d): B->bar()

View file

@ -2,7 +2,7 @@
Bug #48004 (Error handler prevents creation of default object)
--FILE--
<?php
function error_handler($errno, $errstr, $errfile, $errline, $errcontext) {
function error_handler($errno, $errstr, $errfile, $errline) {
return true;
}

View file

@ -15,6 +15,6 @@ $a = $empty($b);
--EXPECTF--
Fatal error: Uncaught Exception: error! in %sbug51394.php:%d
Stack trace:
#0 %sbug51394.php(%d): eh(8, 'Undefined varia%s', '%s', %d, Array)
#0 %sbug51394.php(%d): eh(8, 'Undefined varia%s', '%s', %d)
#1 {main}
thrown in %sbug51394.php on line %d

View file

@ -13,7 +13,7 @@ require 'notfound.php';
error(require(notfound.php): failed to open stream: %s)
Warning: Uncaught Exception: Foo in %sbug60909_1.php:5
Stack trace:
#0 %sbug60909_1.php(8): {closure}(2, 'require(notfoun...', '%s', 8, Array)
#0 %sbug60909_1.php(8): {closure}(2, 'require(notfoun...', '%s', 8)
#1 %sbug60909_1.php(8): require()
#2 {main}
thrown in %sbug60909_1.php on line 5

View file

@ -19,7 +19,7 @@ Error handler called (Undefined variable: undefined)
Fatal error: Uncaught ErrorException: Undefined variable: undefined in %sbug61767.php:%d
Stack trace:
#0 %sbug61767.php(%d): {closure}(%s, 'Undefined varia...', '%s', %d, Array)
#0 %sbug61767.php(%d): {closure}(%s, 'Undefined varia...', '%s', %d)
#1 {main}
thrown in %sbug61767.php on line %d
Shutting down

View file

@ -33,7 +33,7 @@ Notice: ob_end_flush(): failed to delete and flush buffer. No buffer to delete o
Fatal error: Uncaught Exception in %sbug64960.php:19
Stack trace:
#0 [internal function]: {closure}(8, 'ob_end_clean():...', '%s', 9, Array)
#0 [internal function]: {closure}(8, 'ob_end_clean():...', '%s', 9)
#1 %sbug64960.php(9): ob_end_clean()
#2 [internal function]: ExceptionHandler->__invoke(Object(Exception))
#3 {main}

View file

@ -3,7 +3,7 @@ Bug #69388: Use after free on recursive calls to PHP compiler
--FILE--
<?php
function handle_error($code, $message, $file, $line, $context) {
function handle_error($code, $message, $file, $line) {
if (!function_exists("bla")) {
eval('function bla($s) {echo "$s\n";}');
}

View file

@ -2,7 +2,7 @@
Bug #69388 - Variation
--FILE--
<?php
function handle_error($code, $message, $file, $line, $context) {
function handle_error($code, $message, $file, $line) {
eval('namespace Foo;');
echo "$message\n";
}

View file

@ -13,7 +13,7 @@ set_error_handler(
--EXPECTF--
Fatal error: Uncaught Exception: My custom error in %s:%d
Stack trace:
#0 %s(%d): {closure}(8, 'A non well form...', '%s', %d, Array)
#0 %s(%d): {closure}(8, 'A non well form...', '%s', %d)
#1 %s(%d): {closure}('7as')
#2 {main}
thrown in %s on line %d

View file

@ -76,7 +76,7 @@ $foo->bar($a, $b, $c);
--EXPECTF--
Fatal error: Uncaught Error: Class 'DoesNotExists' not found in %sbug72101.php:61
Stack trace:
#0 %sbug72101.php(8): {closure}(2, 'Parameter 1 to ...', '%s', 8, Array)
#0 %sbug72101.php(8): {closure}(2, 'Parameter 1 to ...', '%s', 8)
#1 %sbug72101.php(27): PHPUnit_Framework_MockObject_Stub_ReturnCallback->invoke(Object(PHPUnit_Framework_MockObject_Invocation_Static))
#2 %sbug72101.php(19): PHPUnit_Framework_MockObject_Matcher->invoked(Object(PHPUnit_Framework_MockObject_Invocation_Static))
#3 %sbug72101.php(52): PHPUnit_Framework_MockObject_InvocationMocker->invoke(Object(PHPUnit_Framework_MockObject_Invocation_Static))

View file

@ -13,6 +13,6 @@ $c = $b[$a];
--EXPECTF--
Fatal error: Uncaught Exception: blah in %sbug76025.php:%d
Stack trace:
#0 %sbug76025.php(%d): handleError(8, 'Undefined varia...', '%s', %d, Array)
#0 %sbug76025.php(%d): handleError(8, 'Undefined varia...', '%s', %d)
#1 {main}
thrown in %sbug76025.php on line %d

View file

@ -12,6 +12,6 @@ $y = &$x["bar"];
--EXPECTF--
Fatal error: Uncaught Exception: Illegal string offset 'bar' in %sbug76534.php:%d
Stack trace:
#0 %sbug76534.php(%d): {closure}(2, 'Illegal string ...', '%s', %d, Array)
#0 %sbug76534.php(%d): {closure}(2, 'Illegal string ...', '%s', %d)
#1 {main}
thrown in %sbug76534.php on line %d

View file

@ -2,7 +2,7 @@
Test nowdoc and line numbering
--FILE--
<?php
function error_handler($num, $msg, $file, $line, $vars) {
function error_handler($num, $msg, $file, $line) {
echo $line,"\n";
}
set_error_handler('error_handler');

View file

@ -1246,7 +1246,7 @@ static ZEND_COLD void zend_error_va_list(int type, const char *format, va_list a
va_list args;
#endif
va_list usr_copy;
zval params[5];
zval params[4];
zval retval;
const char *error_filename;
uint32_t error_lineno = 0;
@ -1255,7 +1255,6 @@ static ZEND_COLD void zend_error_va_list(int type, const char *format, va_list a
zend_class_entry *saved_class_entry;
zend_stack loop_var_stack;
zend_stack delayed_oplines_stack;
zend_array *symbol_table;
zend_class_entry *orig_fake_scope;
/* Report about uncaught exception in case of fatal errors */
@ -1385,15 +1384,6 @@ static ZEND_COLD void zend_error_va_list(int type, const char *format, va_list a
ZVAL_LONG(&params[3], error_lineno);
symbol_table = zend_rebuild_symbol_table();
/* during shutdown the symbol table table can be still null */
if (!symbol_table) {
ZVAL_NULL(&params[4]);
} else {
ZVAL_ARR(&params[4], zend_array_dup(symbol_table));
}
ZVAL_COPY_VALUE(&orig_user_error_handler, &EG(user_error_handler));
ZVAL_UNDEF(&EG(user_error_handler));
@ -1414,7 +1404,7 @@ static ZEND_COLD void zend_error_va_list(int type, const char *format, va_list a
orig_fake_scope = EG(fake_scope);
EG(fake_scope) = NULL;
if (call_user_function(CG(function_table), NULL, &orig_user_error_handler, &retval, 5, params) == SUCCESS) {
if (call_user_function(CG(function_table), NULL, &orig_user_error_handler, &retval, 4, params) == SUCCESS) {
if (Z_TYPE(retval) != IS_UNDEF) {
if (Z_TYPE(retval) == IS_FALSE) {
zend_error_cb(type, error_filename, error_lineno, format, args);
@ -1435,7 +1425,6 @@ static ZEND_COLD void zend_error_va_list(int type, const char *format, va_list a
CG(in_compilation) = 1;
}
zval_ptr_dtor(&params[4]);
zval_ptr_dtor(&params[2]);
zval_ptr_dtor(&params[1]);

View file

@ -6,7 +6,7 @@ iconv_mime_decode()
iconv.internal_charset=iso-8859-1
--FILE--
<?php
function my_error_handler($errno, $errmsg, $filename, $linenum, $vars)
function my_error_handler($errno, $errmsg, $filename, $linenum)
{
echo "$errno: $errmsg\n";
}

View file

@ -6,7 +6,7 @@ iconv_mime_encode()
iconv.internal_charset=iso-8859-1
--FILE--
<?php
function my_error_handler($errno, $errmsg, $filename, $linenum, $vars)
function my_error_handler($errno, $errmsg, $filename, $linenum)
{
echo "$errno: $errmsg\n";
}

View file

@ -6,7 +6,7 @@ iconv_strpos()
iconv.internal_charset=ISO-8859-1
--FILE--
<?php
function my_error_handler($errno, $errmsg, $filename, $linenum, $vars)
function my_error_handler($errno, $errmsg, $filename, $linenum)
{
echo "$errno: $errmsg\n";
}

View file

@ -6,7 +6,7 @@ iconv_strrpos()
iconv.internal_charset=ISO-8859-1
--FILE--
<?php
function my_error_handler($errno, $errmsg, $filename, $linenum, $vars)
function my_error_handler($errno, $errmsg, $filename, $linenum)
{
echo "$errno: $errmsg\n";
}

View file

@ -4,7 +4,7 @@
*/
// Custom Error Hanlder for testing
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
global $debug;
$err_type = array (

View file

@ -16,7 +16,7 @@ function_exists('mb_substitute_character') or die("skip mb_substitute_character(
echo "*** Testing mb_substitute_character() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -18,7 +18,7 @@ echo "*** Test substituting argument 1 with object values ***\n";
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -12,7 +12,7 @@ echo "*** Testing class_implements() : variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -12,7 +12,7 @@ echo "*** Testing class_uses() : variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -19,7 +19,7 @@ class classWithoutToString
}
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -15,7 +15,7 @@ $array2 = array('blue' => 1, 'red' => 2, 'green' => 3, 'purple' => 4);
$array3 = array(1, 2, 3, 4, 5);
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -14,7 +14,7 @@ $array1 = array("a" => "green", "b" => "brown", "c" => "blue", "red");
$array2 = array("a" => "green", "yellow", "red");
$array3 = array("a"=>"green", "brown");
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -15,7 +15,7 @@ $array2 = array('green' => 5, 'blue' => 6, 'yellow' => 7, 'cyan' => 8);
$array3 = array("a"=>"green", "cyan");
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -11,7 +11,7 @@ Test array_multisort() function : usage variation
echo "*** Testing array_multisort() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -11,7 +11,7 @@ Test array_multisort() function : usage variation
echo "*** Testing array_multisort() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -11,7 +11,7 @@ Test array_multisort() function : usage variation
echo "*** Testing array_multisort() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -11,7 +11,7 @@ Test array_multisort() function : usage variation - test sort order of all types
echo "*** Testing array_multisort() : usage variation - test sort order of all types***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
// We're testing sort order not errors so ignore.
}
set_error_handler('test_error_handler');

View file

@ -9,7 +9,7 @@ Test get_class_methods() function : usage variations - unexpected types
*/
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
set_error_handler('test_error_handler');

View file

@ -12,7 +12,7 @@ spl_autoload_register(function ($className) {
echo "In autoload($className)\n";
});
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
set_error_handler('test_error_handler');

View file

@ -12,7 +12,7 @@ spl_autoload_register(function ($className) {
echo "In autoload($className)\n";
});
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
set_error_handler('test_error_handler');

View file

@ -12,7 +12,7 @@ spl_autoload_register(function ($className) {
echo "In autoload($className)\n";
});
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
set_error_handler('test_error_handler');

View file

@ -12,7 +12,7 @@ spl_autoload_register(function ($className) {
echo "In autoload($className)\n";
});
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
set_error_handler('test_error_handler');

View file

@ -13,7 +13,7 @@ Dave Kelsey <d_kelsey@uk.ibm.com>
echo "*** Testing file_put_contents() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -13,7 +13,7 @@ Dave Kelsey <d_kelsey@uk.ibm.com>
echo "*** Testing file_put_contents() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -11,7 +11,7 @@ Test intval() function : usage variation
echo "*** Testing intval() : usage variation ***\n";
// Define error handler
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
if (error_reporting() != 0) {
// report non-silenced errors
echo "Error: $err_no - $err_msg, $filename($linenum)\n";

View file

@ -8,7 +8,7 @@ Test getimagesize() function : usage variations - unexpected type for arg 2
* Alias to functions:
*/
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
echo "Error: $err_no - $err_msg, $filename($linenum)\n";
}
set_error_handler('test_error_handler');

View file

@ -2,7 +2,7 @@
Object to string conversion: error cases and behaviour variations.
--FILE--
<?php
function test_error_handler($err_no, $err_msg, $filename, $linenum, $vars) {
function test_error_handler($err_no, $err_msg, $filename, $linenum) {
echo "Error: $err_no - $err_msg\n";
}
set_error_handler('test_error_handler');

View file

@ -3,7 +3,7 @@ Bug #25547 (error_handler and array index with function call)
--FILE--
<?php
function handler($errno, $errstr, $errfile, $errline, $context)
function handler($errno, $errstr, $errfile, $errline)
{
echo __FUNCTION__ . "($errstr)\n";
}