com php-src: Implemented FR #45235 A way to clear or reset the results for error_get_last(): ext/standard/basic_functions. c
ext/standard/basic_functions.h ext/standard/tests/gen eral_functions/error_clear_last.phpt
| From: | Stanislav Malyshev | Date: | Tue, 03 Mar 2015 09:48:03 +0000 |
| Subject: | com php-src: Implemented FR #45235 A way to clear or reset the results for error_get_last(): ext/standard/basic_functions. c ext/standard/basic_functions.h ext/standard/tests/gen eral_functions/error_clear_last.phpt |
||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-85369@lists.php.net to get a copy of this message | ||
Commit: 908542c34e436ee06c49d55b93320da28adf1ac0
Author: Reeze Xia <reeze@php.net> Tue, 3 Mar 2015 17:48:03 +0800
Parents: bb2e62ecda3f3935a076063be66b394ac6831c09
Branches: master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=908542c34e436ee06c49d55b93320da28adf1ac0
Log:
Implemented FR #45235 A way to clear or reset the results for error_get_last()
Bugs:
https://bugs.php.net/45235
Changed paths:
M ext/standard/basic_functions.c
M ext/standard/basic_functions.h
A ext/standard/tests/general_functions/error_clear_last.phpt
Diff:
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 26f7209..ec15a4d 100644
--- a/ext/standard/basic_functions.c
+++ b/ext/standard/basic_functions.c
@@ -685,6 +685,9 @@ ZEND_END_ARG_INFO()
ZEND_BEGIN_ARG_INFO_EX(arginfo_error_get_last, 0, 0, 0)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_error_clear_last, 0, 0, 0)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_call_user_func, 0, 0, 1)
ZEND_ARG_INFO(0, function_name)
ZEND_ARG_VARIADIC_INFO(0, parameters)
@@ -2942,6 +2945,7 @@ const zend_function_entry basic_functions[] = { /* {{{ */
PHP_FE(error_log, arginfo_error_log)
PHP_FE(error_get_last, arginfo_error_get_last)
+ PHP_FE(error_clear_last, arginfo_error_clear_last)
PHP_FE(call_user_func, arginfo_call_user_func)
PHP_FE(call_user_func_array, arginfo_call_user_func_array)
PHP_FE(forward_static_call, arginfo_forward_static_call)
@@ -4700,6 +4704,33 @@ PHP_FUNCTION(error_get_last)
}
/* }}} */
+/* {{{ proto bool error_clear_last()
+ Clear the last occurred error. Returns false if there hasn't been an error yet. */
+PHP_FUNCTION(error_clear_last)
+{
+ if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) {
+ return;
+ }
+
+ if (PG(last_error_message)) {
+ PG(last_error_type) = 0;
+ PG(last_error_lineno) = 0;
+
+ free(PG(last_error_message));
+ PG(last_error_message) = NULL;
+
+ if (PG(last_error_file)) {
+ free(PG(last_error_file));
+ PG(last_error_file) = NULL;
+ }
+
+ RETURN_TRUE;
+ }
+
+ RETURN_FALSE;
+}
+/* }}} */
+
/* {{{ proto mixed call_user_func(mixed function_name [, mixed parmeter] [, mixed ...])
Call a user function which is the first parameter
Warning: This function is special-cased by zend_compile.c and so is usually bypassed */
diff --git a/ext/standard/basic_functions.h b/ext/standard/basic_functions.h
index 59f7498..3b69da0 100644
--- a/ext/standard/basic_functions.h
+++ b/ext/standard/basic_functions.h
@@ -81,6 +81,7 @@ PHP_FUNCTION(get_magic_quotes_gpc);
PHP_FUNCTION(error_log);
PHP_FUNCTION(error_get_last);
+PHP_FUNCTION(error_clear_last);
PHP_FUNCTION(call_user_func);
PHP_FUNCTION(call_user_func_array);
diff --git a/ext/standard/tests/general_functions/error_clear_last.phpt
b/ext/standard/tests/general_functions/error_clear_last.phpt
new file mode 100644
index 0000000..b6039d8
--- /dev/null
+++ b/ext/standard/tests/general_functions/error_clear_last.phpt
@@ -0,0 +1,33 @@
+--TEST--
+error_clear_last() tests
+--FILE--
+<?php
+
+var_dump(error_get_last());
+
+var_dump(error_clear_last());
+
+@$a = $b;
+
+var_dump(error_get_last());
+var_dump(error_clear_last());
+var_dump(error_get_last());
+
+echo "Done\n";
+?>
+--EXPECTF--
+NULL
+bool(false)
+array(4) {
+ ["type"]=>
+ int(8)
+ ["message"]=>
+ string(21) "Undefined variable: b"
+ ["file"]=>
+ string(%d) "%s"
+ ["line"]=>
+ int(%d)
+}
+bool(true)
+NULL
+Done