summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorStanislav Malyshev <stas@php.net>2015-03-08 17:24:11 -0700
committerStanislav Malyshev <stas@php.net>2015-03-08 17:26:38 -0700
commit33ef5c47a5dd30d1143bf716a07036f68853daa3 (patch)
tree79910a2b5498bbfe3f3bc59ccb08226c1b766c74
parenta8a77fff5c1835f6861a875e8252d3901b5c0ae1 (diff)
parent916709cf8514e34a39426c6f127bb34096515324 (diff)
downloadphp-git-33ef5c47a5dd30d1143bf716a07036f68853daa3.tar.gz
Merge branch 'pull-request/1135'
* pull-request/1135: Return void like other functions Use zend_parse_parameters_none() Implemented FR #45235 A way to clear or reset the results for error_get_last()
-rw-r--r--NEWS1
-rw-r--r--UPGRADING1
-rw-r--r--ext/standard/basic_functions.c29
-rw-r--r--ext/standard/basic_functions.h1
-rw-r--r--ext/standard/tests/general_functions/error_clear_last.phpt32
5 files changed, 63 insertions, 1 deletions
diff --git a/NEWS b/NEWS
index 44cb817de6..40904fb5bf 100644
--- a/NEWS
+++ b/NEWS
@@ -53,6 +53,7 @@
. Removed support for hexadecimal numeric strings. (Nikita)
. Removed obsolete extensions and SAPIs. See the full list in UPGRADING. (Anatol)
. Added NULL byte protection to exec, system and passthru. (Yasuo)
+ . Added error_clear_last() function. (Reeze Xia)
- Curl:
. Fixed bug #68937 (Segfault in curl_multi_exec). (Laruence)
diff --git a/UPGRADING b/UPGRADING
index 9770c976be..7cc93a3b16 100644
--- a/UPGRADING
+++ b/UPGRADING
@@ -447,6 +447,7 @@ Other
- Standard
. Added intdiv() function for integer division.
+ . Added error_clear_last() function to reset error state.
- Stream:
. Added stream_socket_crypto_info() allowing inspection of negotiated TLS
diff --git a/ext/standard/basic_functions.c b/ext/standard/basic_functions.c
index 6760177a00..c76cba5e0b 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)
@@ -2947,6 +2950,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)
@@ -4696,7 +4700,7 @@ PHPAPI int _php_error_log_ex(int opt_err, char *message, size_t message_len, cha
Get the last occurred error as associative array. Returns NULL if there hasn't been an error yet. */
PHP_FUNCTION(error_get_last)
{
- if (zend_parse_parameters(ZEND_NUM_ARGS(), "") == FAILURE) {
+ if (zend_parse_parameters_none() == FAILURE) {
return;
}
@@ -4710,6 +4714,29 @@ PHP_FUNCTION(error_get_last)
}
/* }}} */
+/* {{{ proto void error_clear_last(void)
+ Clear the last occurred error. */
+PHP_FUNCTION(error_clear_last)
+{
+ if (zend_parse_parameters_none() == 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;
+ }
+ }
+}
+/* }}} */
+
/* {{{ 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 59f7498fb9..3b69da043b 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 0000000000..02936c84cb
--- /dev/null
+++ b/ext/standard/tests/general_functions/error_clear_last.phpt
@@ -0,0 +1,32 @@
+--TEST--
+error_clear_last() tests
+--FILE--
+<?php
+
+var_dump(error_get_last());
+error_clear_last();
+var_dump(error_get_last());
+
+@$a = $b;
+
+var_dump(error_get_last());
+error_clear_last();
+var_dump(error_get_last());
+
+echo "Done\n";
+?>
+--EXPECTF--
+NULL
+NULL
+array(4) {
+ ["type"]=>
+ int(8)
+ ["message"]=>
+ string(21) "Undefined variable: b"
+ ["file"]=>
+ string(%d) "%s"
+ ["line"]=>
+ int(%d)
+}
+NULL
+Done