]> granicus.if.org Git - php/commitdiff
Promote some warnings to Errors in Zend basic functions
authorGeorge Peter Banyard <girgias@php.net>
Sun, 29 Mar 2020 22:40:18 +0000 (00:40 +0200)
committerGeorge Peter Banyard <girgias@php.net>
Tue, 31 Mar 2020 14:32:58 +0000 (16:32 +0200)
Closes GH-5325

21 files changed:
Zend/tests/002.phpt
Zend/tests/003.phpt
Zend/tests/004.phpt
Zend/tests/006.phpt
Zend/tests/011.phpt
Zend/tests/015.phpt
Zend/tests/020.phpt
Zend/tests/exception_handler_004.phpt
Zend/tests/func_get_args.phpt
Zend/zend_builtin_functions.c
Zend/zend_builtin_functions.stub.php
Zend/zend_builtin_functions_arginfo.h
ext/reflection/tests/property_exists.phpt
ext/standard/tests/class_object/property_exists_error.phpt
ext/standard/tests/strings/bug36944.phpt
ext/standard/tests/strings/strncasecmp_error.phpt
ext/standard/tests/strings/strncmp_error.phpt
tests/lang/func_get_arg.003.phpt
tests/lang/func_get_arg.004.phpt
tests/lang/func_get_arg_variation.phpt
tests/lang/func_get_args.003.phpt

index 1311e3b5703e94e05b909ccb03be194add6e63fc..80057bfa53e3c060c5c8381a3974fb0b64084016 100644 (file)
@@ -4,20 +4,53 @@ func_get_arg() tests
 <?php
 
 function test1() {
-    var_dump(func_get_arg(-10));
-    var_dump(func_get_arg(0));
-    var_dump(func_get_arg(1));
+    try {
+        var_dump(func_get_arg(-10));
+    } catch (\ValueError $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
+
+    try {
+        var_dump(func_get_arg(0));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
+    try {
+        var_dump(func_get_arg(1));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 }
 
 function test2($a) {
-    var_dump(func_get_arg(0));
-    var_dump(func_get_arg(1));
+    try {
+        var_dump(func_get_arg(0));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
+    try {
+        var_dump(func_get_arg(1));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 }
 
 function test3($a, $b) {
-    var_dump(func_get_arg(0));
-    var_dump(func_get_arg(1));
-    var_dump(func_get_arg(2));
+    try {
+        var_dump(func_get_arg(0));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
+    try {
+        var_dump(func_get_arg(1));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
+    try {
+        var_dump(func_get_arg(2));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 }
 
 test1();
@@ -40,62 +73,49 @@ call_user_func("test3", 1, 2);
 
 class test {
     static function test1($a) {
-        var_dump(func_get_arg(0));
-        var_dump(func_get_arg(1));
+        try {
+            var_dump(func_get_arg(0));
+        } catch (\Error $e) {
+            echo $e->getMessage() . \PHP_EOL;
+        }
+        try {
+            var_dump(func_get_arg(1));
+        } catch (\Error $e) {
+            echo $e->getMessage() . \PHP_EOL;
+        }
     }
 }
 
 test::test1(1);
-var_dump(func_get_arg(1));
+try {
+    var_dump(func_get_arg(1));
+} catch (\Error $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 
 echo "Done\n";
 ?>
 --EXPECTF--
-Warning: func_get_arg():  The argument number should be >= 0 in %s on line %d
-bool(false)
-
-Warning: func_get_arg():  Argument 0 not passed to function in %s on line %d
-bool(false)
-
-Warning: func_get_arg():  Argument 1 not passed to function in %s on line %d
-bool(false)
-
-Warning: func_get_arg():  The argument number should be >= 0 in %s on line %d
-bool(false)
+func_get_arg(): Argument #1 ($arg_num) must be greater than or equal to 0
+func_get_arg(): Argument 0 not passed to function
+func_get_arg(): Argument 1 not passed to function
+func_get_arg(): Argument #1 ($arg_num) must be greater than or equal to 0
 int(10)
-
-Warning: func_get_arg():  Argument 1 not passed to function in %s on line %d
-bool(false)
+func_get_arg(): Argument 1 not passed to function
 int(1)
-
-Warning: func_get_arg():  Argument 1 not passed to function in %s on line %d
-bool(false)
+func_get_arg(): Argument 1 not passed to function
 Exception: Too few arguments to function test2(), 0 passed in %s002.php on line %d and exactly 1 expected
 int(1)
 int(2)
-
-Warning: func_get_arg():  Argument 2 not passed to function in %s on line %d
-bool(false)
-
-Warning: func_get_arg():  The argument number should be >= 0 in %s on line %d
-bool(false)
-
-Warning: func_get_arg():  Argument 0 not passed to function in %s on line %d
-bool(false)
-
-Warning: func_get_arg():  Argument 1 not passed to function in %s on line %d
-bool(false)
-Exception: Too few arguments to function test3(), 1 passed in %s002.php on line %d and exactly 2 expected
+func_get_arg(): Argument 2 not passed to function
+func_get_arg(): Argument #1 ($arg_num) must be greater than or equal to 0
+func_get_arg(): Argument 0 not passed to function
+func_get_arg(): Argument 1 not passed to function
+Exception: Too few arguments to function test3(), 1 passed in %s on line %d and exactly 2 expected
 int(1)
 int(2)
-
-Warning: func_get_arg():  Argument 2 not passed to function in %s on line %d
-bool(false)
+func_get_arg(): Argument 2 not passed to function
 int(1)
-
-Warning: func_get_arg():  Argument 1 not passed to function in %s on line %d
-bool(false)
-
-Warning: func_get_arg():  Called from the global scope - no function context in %s on line %d
-bool(false)
+func_get_arg(): Argument 1 not passed to function
+func_get_arg() cannot be called from the global scope
 Done
index 6680956f7e9a668b7e8d196095961908c939fe59..3931628e9a9ca14d29334199bcbadda4e90c6a3b 100644 (file)
@@ -40,9 +40,13 @@ class test {
 }
 
 test::test1(1);
-var_dump(func_get_args());
 
-echo "Done\n";
+try {
+    var_dump(func_get_args());
+} catch (\Error $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+
 ?>
 --EXPECTF--
 array(0) {
@@ -75,7 +79,4 @@ array(1) {
   [0]=>
   int(1)
 }
-
-Warning: func_get_args():  Called from the global scope - no function context in %s on line %d
-bool(false)
-Done
+func_get_args() cannot be called from the global scope
index 2f733f1bd886ba361cd9c3d034e3a2da7f83c2ff..b5b476cc1beead13735eaa6e1df7a398ef78a6ad 100644 (file)
@@ -4,19 +4,19 @@ strncmp() tests
 <?php
 
 var_dump(strncmp("", "", 100));
-var_dump(strncmp("aef", "dfsgbdf", -1));
+try {
+    var_dump(strncmp("aef", "dfsgbdf", -1));
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 var_dump(strncmp("fghjkl", "qwer", 0));
 var_dump(strncmp("qwerty", "qwerty123", 6));
 var_dump(strncmp("qwerty", "qwerty123", 7));
 
-echo "Done\n";
 ?>
---EXPECTF--
+--EXPECT--
 int(0)
-
-Warning: Length must be greater than or equal to 0 in %s on line %d
-bool(false)
+strncmp(): Argument #3 ($len) must be greater than or equal to 0
 int(0)
 int(0)
 int(-1)
-Done
index 12907fd36eea84aa6e2a31473052d1bcb3de41d4..3377e933ce2af137c7b427c3eaef63e45ce0614e 100644 (file)
@@ -3,7 +3,12 @@ strncasecmp() tests
 --FILE--
 <?php
 
-var_dump(strncasecmp("", "", -1));
+try {
+    var_dump(strncasecmp("", "", -1));
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+
 var_dump(strncasecmp("aef", "dfsgbdf", 0));
 var_dump(strncasecmp("aef", "dfsgbdf", 10));
 var_dump(strncasecmp("qwe", "qwer", 3));
@@ -12,11 +17,9 @@ var_dump(strncasecmp("qwErtY", "qwer", 7));
 var_dump(strncasecmp("q123", "Q123", 3));
 var_dump(strncasecmp("01", "01", 1000));
 
-echo "Done\n";
 ?>
---EXPECTF--
-Warning: Length must be greater than or equal to 0 in %s on line %d
-bool(false)
+--EXPECT--
+strncasecmp(): Argument #3 ($len) must be greater than or equal to 0
 int(0)
 int(-3)
 int(0)
@@ -24,4 +27,3 @@ int(0)
 int(2)
 int(0)
 int(0)
-Done
index 36213af171e2a40c0858bf5230c882e90eff77a9..0a7e3fd90a11e2f02a34d14c4da19fdae0ab90b4 100644 (file)
@@ -39,18 +39,40 @@ var_dump(property_exists($foo,"pp2"));
 var_dump(property_exists($foo,"pp3"));
 var_dump(property_exists($foo,"nonexistent"));
 var_dump(property_exists($foo,""));
-var_dump(property_exists(array(),"test"));
-var_dump(property_exists(1,"test"));
-var_dump(property_exists(true,"test"));
+
+try {
+    var_dump(property_exists(array(), "test"));
+} catch (\TypeError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+try {
+    var_dump(property_exists(1, "test"));
+} catch (\TypeError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+try {
+    var_dump(property_exists(3.14, "test"));
+} catch (\TypeError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+try {
+    var_dump(property_exists(true, "test"));
+} catch (\TypeError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+try {
+    var_dump(property_exists(null, "test"));
+} catch (\TypeError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 
 $foo->bar();
 
 $bar = new bar;
 $bar->test();
 
-echo "Done\n";
 ?>
---EXPECTF--
+--EXPECT--
 bool(true)
 bool(true)
 bool(true)
@@ -64,19 +86,14 @@ bool(true)
 bool(true)
 bool(false)
 bool(false)
-
-Warning: First parameter must either be an object or the name of an existing class in %s on line %d
-NULL
-
-Warning: First parameter must either be an object or the name of an existing class in %s on line %d
-NULL
-
-Warning: First parameter must either be an object or the name of an existing class in %s on line %d
-NULL
+property_exists(): Argument #1 ($object_or_class) must be of type object|string, array given
+property_exists(): Argument #1 ($object_or_class) must be of type object|string, int given
+property_exists(): Argument #1 ($object_or_class) must be of type object|string, float given
+property_exists(): Argument #1 ($object_or_class) must be of type object|string, bool given
+property_exists(): Argument #1 ($object_or_class) must be of type object|string, null given
 bool(true)
 bool(true)
 bool(true)
 bool(true)
 bool(true)
 bool(true)
-Done
index deea89d14d87acf8f027b3e59a71f07f35ab5d4c..8c4dd62d397a300b8d0e0c4d3e516c37929d1a4f 100644 (file)
@@ -4,26 +4,30 @@ trigger_error() tests
 <?php
 
 var_dump(trigger_error("error"));
-var_dump(trigger_error("error", -1));
-var_dump(trigger_error("error", 0));
+
+try {
+    var_dump(trigger_error("error", -1));
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+try {
+    var_dump(trigger_error("error", 0));
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+
 var_dump(trigger_error("error", E_USER_WARNING));
 var_dump(trigger_error("error", E_USER_DEPRECATED));
 
-echo "Done\n";
 ?>
 --EXPECTF--
 Notice: error in %s on line %d
 bool(true)
-
-Warning: Invalid error type specified in %s on line %d
-bool(false)
-
-Warning: Invalid error type specified in %s on line %d
-bool(false)
+trigger_error(): Argument #2 ($error_type) must be one of E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, or E_USER_DEPRECATED
+trigger_error(): Argument #2 ($error_type) must be one of E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE, or E_USER_DEPRECATED
 
 Warning: error in %s on line %d
 bool(true)
 
 Deprecated: error in %s on line %d
 bool(true)
-Done
index dc7a34be06fc7ccbf1497afe9adfb42c8aa67063..9e36037d8862f86ea669ff0b2b1694840bf1b594 100644 (file)
@@ -3,7 +3,11 @@ func_get_arg() invalid usage
 --FILE--
 <?php
 
-var_dump(func_get_arg(1));
+try {
+    var_dump(func_get_arg(1));
+} catch (\Error $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 
 function bar() {
     var_dump(func_get_arg(1));
@@ -13,14 +17,13 @@ function foo() {
     bar(func_get_arg(1));
 }
 
-foo(1,2);
+try {
+    foo(1,2);
+} catch (\Error $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 
-echo "Done\n";
 ?>
---EXPECTF--
-Warning: func_get_arg():  Called from the global scope - no function context in %s on line %d
-bool(false)
-
-Warning: func_get_arg():  Argument 1 not passed to function in %s on line %d
-bool(false)
-Done
+--EXPECT--
+func_get_arg() cannot be called from the global scope
+func_get_arg(): Argument 1 not passed to function
index 757a1b7f2d3d181cd35589edc048a9c50bac96a8..f07970d3377f7ac64dde18f29bb6263a50eaff59 100644 (file)
@@ -3,13 +3,18 @@ exception handler tests - 4
 --FILE--
 <?php
 
-set_exception_handler("fo");
-set_exception_handler(array("", ""));
+try {
+    set_exception_handler("fo");
+} catch (\TypeError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+try {
+    set_exception_handler(array("", ""));
+} catch (\TypeError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 
-echo "Done\n";
 ?>
---EXPECTF--
-Warning: set_exception_handler(): Argument #1 ($exception_handler) must be a valid callback in %s on line %d
-
-Warning: set_exception_handler(): Argument #1 ($exception_handler) must be a valid callback in %s on line %d
-Done
+--EXPECT--
+set_exception_handler(): Argument #1 ($exception_handler) must be a valid callback
+set_exception_handler(): Argument #1 ($exception_handler) must be a valid callback
index eea8ae4354eebb466ab91395b3011c983c124105..33cfdb02ebcd285f24dd7f6a5d7c396d34cbec1c 100644 (file)
@@ -1,10 +1,14 @@
 --TEST--
-Testing func_get_args()
+Testing func_get_args() throws error when called from the global scope
 --FILE--
 <?php
 
-func_get_args();
+try {
+    func_get_args();
+} catch (\Error $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 
 ?>
---EXPECTF--
-Warning: func_get_args():  Called from the global scope - no function context in %s on line 3
+--EXPECT--
+func_get_args() cannot be called from the global scope
index f00996619a4829aaf8d63268ec2377ff149e79a8..3b0e05c21283e2714b880f9d1c2475c79fc4762a 100644 (file)
@@ -97,8 +97,8 @@ static const zend_function_entry builtin_functions[] = { /* {{{ */
        ZEND_FE(strlen,                 arginfo_strlen)
        ZEND_FE(strcmp,                 arginfo_strcmp)
        ZEND_FE(strncmp,                arginfo_strncmp)
-       ZEND_FE(strcasecmp,             arginfo_strcmp)
-       ZEND_FE(strncasecmp,            arginfo_strncmp)
+       ZEND_FE(strcasecmp,             arginfo_strcasecmp)
+       ZEND_FE(strncasecmp,            arginfo_strncasecmp)
        ZEND_FE(error_reporting,        arginfo_error_reporting)
        ZEND_FE(define,                 arginfo_define)
        ZEND_FE(defined,                arginfo_defined)
@@ -310,25 +310,25 @@ ZEND_FUNCTION(func_get_arg)
        }
 
        if (requested_offset < 0) {
-               zend_error(E_WARNING, "func_get_arg():  The argument number should be >= 0");
-               RETURN_FALSE;
+               zend_argument_value_error(1, "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
 
        ex = EX(prev_execute_data);
        if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
-               zend_error(E_WARNING, "func_get_arg():  Called from the global scope - no function context");
-               RETURN_FALSE;
+               zend_throw_error(NULL, "func_get_arg() cannot be called from the global scope");
+               RETURN_THROWS();
        }
 
        if (zend_forbid_dynamic_call("func_get_arg()") == FAILURE) {
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
 
        arg_count = ZEND_CALL_NUM_ARGS(ex);
 
        if ((zend_ulong)requested_offset >= arg_count) {
-               zend_error(E_WARNING, "func_get_arg():  Argument " ZEND_LONG_FMT " not passed to function", requested_offset);
-               RETURN_FALSE;
+               zend_throw_error(NULL, "func_get_arg(): Argument " ZEND_LONG_FMT " not passed to function", requested_offset);
+               RETURN_THROWS();
        }
 
        first_extra_arg = ex->func->op_array.num_args;
@@ -353,12 +353,12 @@ ZEND_FUNCTION(func_get_args)
        zend_execute_data *ex = EX(prev_execute_data);
 
        if (ZEND_CALL_INFO(ex) & ZEND_CALL_CODE) {
-               zend_error(E_WARNING, "func_get_args():  Called from the global scope - no function context");
-               RETURN_FALSE;
+               zend_throw_error(NULL, "func_get_args() cannot be called from the global scope");
+               RETURN_THROWS();
        }
 
        if (zend_forbid_dynamic_call("func_get_args()") == FAILURE) {
-               RETURN_FALSE;
+               RETURN_THROWS();
        }
 
        arg_count = ZEND_CALL_NUM_ARGS(ex);
@@ -455,8 +455,8 @@ ZEND_FUNCTION(strncmp)
        ZEND_PARSE_PARAMETERS_END();
 
        if (len < 0) {
-               zend_error(E_WARNING, "Length must be greater than or equal to 0");
-               RETURN_FALSE;
+               zend_argument_value_error(3, "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
 
        RETURN_LONG(zend_binary_strncmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2), len));
@@ -492,8 +492,8 @@ ZEND_FUNCTION(strncasecmp)
        ZEND_PARSE_PARAMETERS_END();
 
        if (len < 0) {
-               zend_error(E_WARNING, "Length must be greater than or equal to 0");
-               RETURN_FALSE;
+               zend_argument_value_error(3, "must be greater than or equal to 0");
+               RETURN_THROWS();
        }
 
        RETURN_LONG(zend_binary_strncasecmp(ZSTR_VAL(s1), ZSTR_LEN(s1), ZSTR_VAL(s2), ZSTR_LEN(s2), len));
@@ -725,8 +725,8 @@ ZEND_FUNCTION(get_class)
                if (scope) {
                        RETURN_STR_COPY(scope->name);
                } else {
-                       zend_error(E_WARNING, "get_class() called without object from outside a class");
-                       RETURN_FALSE;
+                       zend_throw_error(NULL, "get_class() without arguments must be called from within a class");
+                       RETURN_THROWS();
                }
        }
 
@@ -743,15 +743,12 @@ ZEND_FUNCTION(get_called_class)
        ZEND_PARSE_PARAMETERS_NONE();
 
        called_scope = zend_get_called_scope(execute_data);
-       if (called_scope) {
-               RETURN_STR_COPY(called_scope->name);
-       } else {
-               zend_class_entry *scope = zend_get_executed_scope();
-               if (!scope)  {
-                       zend_error(E_WARNING, "get_called_class() called from outside a class");
-               }
+       if (!called_scope) {
+               zend_throw_error(NULL, "get_called_class() must be called from within a class");
+               RETURN_THROWS();
        }
-       RETURN_FALSE;
+
+       RETURN_STR_COPY(called_scope->name);
 }
 /* }}} */
 
@@ -1166,8 +1163,8 @@ ZEND_FUNCTION(property_exists)
        } else if (Z_TYPE_P(object) == IS_OBJECT) {
                ce = Z_OBJCE_P(object);
        } else {
-               zend_error(E_WARNING, "First parameter must either be an object or the name of an existing class");
-               RETURN_NULL();
+               zend_argument_type_error(1, "must be of type object|string, %s given", zend_zval_type_name(object));
+               RETURN_THROWS();
        }
 
        property_info = zend_hash_find_ptr(&ce->properties_info, property);
@@ -1348,12 +1345,14 @@ ZEND_FUNCTION(trigger_error)
                case E_USER_DEPRECATED:
                        break;
                default:
-                       zend_error(E_WARNING, "Invalid error type specified");
-                       RETURN_FALSE;
+                       zend_argument_value_error(2, "must be one of E_USER_ERROR, E_USER_WARNING, E_USER_NOTICE,"
+                               " or E_USER_DEPRECATED");
+                       RETURN_THROWS();
                        break;
        }
 
        zend_error((int)error_type, "%s", message);
+       // TODO Change to void
        RETURN_TRUE;
 }
 /* }}} */
@@ -1372,9 +1371,9 @@ ZEND_FUNCTION(set_error_handler)
        if (Z_TYPE_P(error_handler) != IS_NULL) { /* NULL == unset */
                if (!zend_is_callable(error_handler, 0, NULL)) {
                        zend_string *error_handler_name = zend_get_callable_name(error_handler);
-                       zend_error(E_WARNING, "%s(): Argument #1 ($error_handler) must be a valid callback", get_active_function_name());
+                       zend_argument_type_error(1, "must be a valid callback");
                        zend_string_release_ex(error_handler_name, 0);
-                       return;
+                       RETURN_THROWS();
                }
        }
 
@@ -1419,6 +1418,8 @@ ZEND_FUNCTION(restore_error_handler)
                ZVAL_COPY_VALUE(&EG(user_error_handler), tmp);
                zend_stack_del_top(&EG(user_error_handlers));
        }
+
+       // TODO Change to void
        RETURN_TRUE;
 }
 /* }}} */
@@ -1436,9 +1437,9 @@ ZEND_FUNCTION(set_exception_handler)
        if (Z_TYPE_P(exception_handler) != IS_NULL) { /* NULL == unset */
                if (!zend_is_callable(exception_handler, 0, NULL)) {
                zend_string *exception_handler_name = zend_get_callable_name(exception_handler);
-                       zend_error(E_WARNING, "%s(): Argument #1 ($exception_handler) must be a valid callback", get_active_function_name());
+                       zend_argument_type_error(1, "must be a valid callback");
                        zend_string_release_ex(exception_handler_name, 0);
-                       return;
+                       RETURN_THROWS();
                }
        }
 
@@ -1473,6 +1474,8 @@ ZEND_FUNCTION(restore_exception_handler)
                ZVAL_COPY_VALUE(&EG(user_exception_handler), tmp);
                zend_stack_del_top(&EG(user_exception_handlers));
        }
+
+       // TODO Change to void
        RETURN_TRUE;
 }
 /* }}} */
index 47f0869869f3ac7f4ed2146b3a7f0157253cd17b..6f2f9f25f3fa939e8dc810092ca9bcabae37c9e3 100644 (file)
@@ -7,13 +7,17 @@ function func_num_args(): int {}
 /** @return mixed */
 function func_get_arg(int $arg_num) {}
 
-function func_get_args(): array|false {}
+function func_get_args(): array {}
 
 function strlen(string $str): int {}
 
 function strcmp(string $str1, string $str2): int {}
 
-function strncmp(string $str1, string $str2, int $len): int|false {}
+function strncmp(string $str1, string $str2, int $len): int {}
+
+function strcasecmp(string $str1, string $str2): int {}
+
+function strncasecmp(string $str1, string $str2, int $len): int {}
 
 function error_reporting($new_error_level = UNKNOWN): int {}
 
@@ -21,9 +25,9 @@ function define(string $constant_name, $value, bool $case_insensitive = false):
 
 function defined(string $constant_name): bool {}
 
-function get_class(object $object = UNKNOWN): string|false {}
+function get_class(object $object = UNKNOWN): string {}
 
-function get_called_class(): string|false {}
+function get_called_class(): string {}
 
 function get_parent_class($object = UNKNOWN): string|false {}
 
@@ -41,7 +45,7 @@ function get_class_methods($class): ?array {}
 
 function method_exists($object_or_class, string $method): bool {}
 
-function property_exists($object_or_class, string $property_name): ?bool {}
+function property_exists($object_or_class, string $property_name): bool {}
 
 function class_exists(string $classname, bool $autoload = true): bool {}
 
index 3b1df2ab497bdd43f1a3a7552d1c34248bc146fb..1dd9b6f712c53a25746db898be5df3b239f66895 100644 (file)
@@ -10,7 +10,7 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_func_get_arg, 0, 0, 1)
        ZEND_ARG_TYPE_INFO(0, arg_num, IS_LONG, 0)
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_func_get_args, 0, 0, MAY_BE_ARRAY|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_func_get_args, 0, 0, IS_ARRAY, 0)
 ZEND_END_ARG_INFO()
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_strlen, 0, 1, IS_LONG, 0)
@@ -22,13 +22,17 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_strcmp, 0, 2, IS_LONG, 0)
        ZEND_ARG_TYPE_INFO(0, str2, IS_STRING, 0)
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_strncmp, 0, 3, MAY_BE_LONG|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_strncmp, 0, 3, IS_LONG, 0)
        ZEND_ARG_TYPE_INFO(0, str1, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO(0, str2, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO(0, len, IS_LONG, 0)
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_error_reporting, 0, 0, IS_LONG, 0)
+#define arginfo_strcasecmp arginfo_strcmp
+
+#define arginfo_strncasecmp arginfo_strncmp
+
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_error_reporting, 0, 0, IS_LONG, 1)
        ZEND_ARG_INFO(0, new_error_level)
 ZEND_END_ARG_INFO()
 
@@ -42,12 +46,11 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_defined, 0, 1, _IS_BOOL, 0)
        ZEND_ARG_TYPE_INFO(0, constant_name, IS_STRING, 0)
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_get_class, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_get_class, 0, 0, IS_STRING, 0)
        ZEND_ARG_TYPE_INFO(0, object, IS_OBJECT, 0)
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_get_called_class, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
-ZEND_END_ARG_INFO()
+#define arginfo_get_called_class arginfo_zend_version
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_MASK_EX(arginfo_get_parent_class, 0, 0, MAY_BE_STRING|MAY_BE_FALSE)
        ZEND_ARG_INFO(0, object)
@@ -80,7 +83,7 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_method_exists, 0, 2, _IS_BOOL, 0
        ZEND_ARG_TYPE_INFO(0, method, IS_STRING, 0)
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_property_exists, 0, 2, _IS_BOOL, 1)
+ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_property_exists, 0, 2, _IS_BOOL, 0)
        ZEND_ARG_INFO(0, object_or_class)
        ZEND_ARG_TYPE_INFO(0, property_name, IS_STRING, 0)
 ZEND_END_ARG_INFO()
@@ -107,10 +110,9 @@ ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_class_alias, 0, 2, _IS_BOOL, 0)
        ZEND_ARG_TYPE_INFO(0, autoload, _IS_BOOL, 0)
 ZEND_END_ARG_INFO()
 
-ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_get_included_files, 0, 0, IS_ARRAY, 0)
-ZEND_END_ARG_INFO()
+#define arginfo_get_included_files arginfo_func_get_args
 
-#define arginfo_get_required_files arginfo_get_included_files
+#define arginfo_get_required_files arginfo_func_get_args
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_trigger_error, 0, 1, _IS_BOOL, 0)
        ZEND_ARG_TYPE_INFO(0, message, IS_STRING, 0)
@@ -133,17 +135,17 @@ ZEND_END_ARG_INFO()
 
 #define arginfo_restore_exception_handler arginfo_restore_error_handler
 
-#define arginfo_get_declared_classes arginfo_get_included_files
+#define arginfo_get_declared_classes arginfo_func_get_args
 
-#define arginfo_get_declared_traits arginfo_get_included_files
+#define arginfo_get_declared_traits arginfo_func_get_args
 
-#define arginfo_get_declared_interfaces arginfo_get_included_files
+#define arginfo_get_declared_interfaces arginfo_func_get_args
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_get_defined_functions, 0, 0, IS_ARRAY, 0)
        ZEND_ARG_TYPE_INFO(0, exclude_disabled, _IS_BOOL, 0)
 ZEND_END_ARG_INFO()
 
-#define arginfo_get_defined_vars arginfo_get_included_files
+#define arginfo_get_defined_vars arginfo_func_get_args
 
 ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX(arginfo_get_resource_type, 0, 1, IS_STRING, 0)
        ZEND_ARG_INFO(0, res)
@@ -195,4 +197,4 @@ ZEND_END_ARG_INFO()
 
 #define arginfo_gc_disable arginfo_gc_enable
 
-#define arginfo_gc_status arginfo_get_included_files
+#define arginfo_gc_status arginfo_func_get_args
index a740589bab9f1617b8b5f8bb99d165d2085433dd..3af7bc4ce6341105f52684c8f2bafea4568cfb6e 100644 (file)
@@ -78,8 +78,16 @@ foreach($pc as $p1) {
 }
 
 echo "===PROBLEMS===\n";
-var_dump(property_exists(NULL, 'empty'));
-var_dump(property_exists(25,'empty'));
+try {
+    var_dump(property_exists(NULL, 'empty'));
+} catch (\TypeError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+try {
+    var_dump(property_exists(25,'empty'));
+} catch (\TypeError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 var_dump(property_exists('',''));
 var_dump(property_exists('A',''));
 var_dump(property_exists('A','123'));
@@ -90,7 +98,7 @@ var_dump(property_exists(new A, '123'));
 var_dump(property_exists(new A, 'init'));
 var_dump(property_exists(new A, 'empty'));
 ?>
---EXPECTF--
+--EXPECT--
 ===A===
 obj(A)::$a
 bool(true)
@@ -202,12 +210,8 @@ bool(true)
 obj(C)::$e
 bool(false)
 ===PROBLEMS===
-
-Warning: First parameter must either be an object or the name of an existing class in %sproperty_exists.php on line %d
-NULL
-
-Warning: First parameter must either be an object or the name of an existing class in %sproperty_exists.php on line %d
-NULL
+property_exists(): Argument #1 ($object_or_class) must be of type object|string, null given
+property_exists(): Argument #1 ($object_or_class) must be of type object|string, int given
 bool(false)
 bool(false)
 bool(false)
index 43f68badd1b45935414982756c98c72083f7ae16..dac3b0f9b1ae70d46955fd80a248cd300896e154 100644 (file)
@@ -12,13 +12,16 @@ echo "*** Testing property_exists() : error conditions ***\n";
 
 echo "\n-- Testing property_exists() function with incorrect arguments --\n";
 $property_name = 'string_val';
-var_dump( property_exists(10, $property_name) );
+
+try {
+    var_dump( property_exists(10, $property_name) );
+} catch (\TypeError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 
 ?>
---EXPECTF--
+--EXPECT--
 *** Testing property_exists() : error conditions ***
 
 -- Testing property_exists() function with incorrect arguments --
-
-Warning: First parameter must either be an object or the name of an existing class in %sproperty_exists_error.php on line %d
-NULL
+property_exists(): Argument #1 ($object_or_class) must be of type object|string, int given
index a9f117fe3f33557bb96071a970ec10c6cef707da..5e3ef4f0a09915f7468e89235dc37aeb46e0f1ae 100644 (file)
@@ -3,24 +3,27 @@ Bug #36944 (strncmp & strncasecmp do not return false on negative string length)
 --FILE--
 <?php
 
-var_dump(strncmp("test ", "e", -1));
+try {
+    var_dump(strncmp("test ", "e", -1));
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 var_dump(strncmp("test ", "e", 10));
 var_dump(strncmp("test ", "e", 0));
 
-var_dump(strncasecmp("test ", "E", -1));
+try {
+    var_dump(strncasecmp("test ", "E", -1));
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 var_dump(strncasecmp("test ", "E", 10));
 var_dump(strncasecmp("test ", "E", 0));
 
-echo "Done\n";
 ?>
 --EXPECTF--
-Warning: Length must be greater than or equal to 0 in %s on line %d
-bool(false)
+strncmp(): Argument #3 ($len) must be greater than or equal to 0
 int(%d)
 int(0)
-
-Warning: Length must be greater than or equal to 0 in %s on line %d
-bool(false)
+strncasecmp(): Argument #3 ($len) must be greater than or equal to 0
 int(%d)
 int(0)
-Done
index 00ddfaed9bdf225311c8a2b84ca1bb425036bc32..f120f4af8200fa3fb18fa6624be69ed407337828 100644 (file)
@@ -11,15 +11,17 @@ echo "*** Testing strncasecmp() function: error conditions ***\n";
 $str1 = 'string_val';
 $str2 = 'string_val';
 
-echo "\n-- Testing strncasecmp() function with invalid argument --";
+echo "-- Testing strncasecmp() function with invalid argument --\n";
 $len = -10;
-var_dump( strncasecmp($str1, $str2, $len) );
-echo "*** Done ***\n";
+
+try {
+    var_dump( strncasecmp($str1, $str2, $len) );
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+
 ?>
---EXPECTF--
+--EXPECT--
 *** Testing strncasecmp() function: error conditions ***
-
 -- Testing strncasecmp() function with invalid argument --
-Warning: Length must be greater than or equal to 0 in %s on line %d
-bool(false)
-*** Done ***
+strncasecmp(): Argument #3 ($len) must be greater than or equal to 0
index 13a4cb0350ac34a3057473f0ed2021071b0e5c07..e67b5d77e97c936516f07f41090dad320e1593d6 100644 (file)
@@ -15,12 +15,14 @@ $str2 = 'string_val';
 
 /* Invalid argument for $len */
 $len = -10;
-var_dump( strncmp($str1, $str2, $len) );
-echo "*** Done ***\n";
+
+try {
+    var_dump( strncmp($str1, $str2, $len) );
+} catch (\ValueError $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
+
 ?>
---EXPECTF--
+--EXPECT--
 *** Testing strncmp() function: error conditions ***
-
-Warning: Length must be greater than or equal to 0 in %s on line %d
-bool(false)
-*** Done ***
+strncmp(): Argument #3 ($len) must be greater than or equal to 0
index 4ef996767411fa5082093561c46c388d3dfc556a..7021f31450750acb954898ae747b86d99fc9879f 100644 (file)
@@ -3,9 +3,12 @@ func_get_arg outside of a function declaration
 --FILE--
 <?php
 
-var_dump (func_get_arg(0));
+try {
+    var_dump(func_get_arg(0));
+} catch (\Error $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 
 ?>
---EXPECTF--
-Warning: func_get_arg():  Called from the global scope - no function context in %s on line %d
-bool(false)
+--EXPECT--
+func_get_arg() cannot be called from the global scope
index 6d0ab20a4efd99719ff5cccf912e90261a2ed9ba..b215b1e51510a8b9559b7b91625139120907de77 100644 (file)
@@ -5,12 +5,14 @@ func_get_arg on non-existent arg
 
 function foo($a)
 {
-    var_dump(func_get_arg(2));
+    try {
+        var_dump(func_get_arg(2));
+    } catch (\Error $e) {
+        echo $e->getMessage() . \PHP_EOL;
+    }
 }
 foo(2, 3);
-echo "\n";
 
 ?>
---EXPECTF--
-Warning: func_get_arg():  Argument 2 not passed to function in %s on line %d
-bool(false)
+--EXPECT--
+func_get_arg(): Argument 2 not passed to function
index bd1fa5b4c5c3cf565f87003fdd0436f03bde5cec..eb608ad0f06d8343a3e84e5a9d1339bc9a8cfbaf 100644 (file)
@@ -6,13 +6,21 @@ func_get_arg test
 function foo($a)
 {
    $a=5;
-   echo func_get_arg(-1);
-   echo func_get_arg(2);
+   try {
+       echo func_get_arg(-1);
+   } catch (\Error $e) {
+       echo $e->getMessage() . \PHP_EOL;
+   }
+
+   try {
+       echo func_get_arg(2);
+   } catch (\Error $e) {
+       echo $e->getMessage() . \PHP_EOL;
+   }
 }
 foo(2);
-echo "\n";
-?>
---EXPECTF--
-Warning: func_get_arg():  The argument number should be >= 0 in %s on line %d
 
-Warning: func_get_arg():  Argument 2 not passed to function in %s on line %d
+?>
+--EXPECT--
+func_get_arg(): Argument #1 ($arg_num) must be greater than or equal to 0
+func_get_arg(): Argument 2 not passed to function
index 844288d90401f251ce72c149037e38bacb36f943..d56de663c5f99ce73376ab461993b7544636e001 100644 (file)
@@ -3,9 +3,12 @@ func_get_args() outside of a function declaration
 --FILE--
 <?php
 
-var_dump(func_get_args());
+try {
+    var_dump(func_get_args());
+} catch (\Error $e) {
+    echo $e->getMessage() . \PHP_EOL;
+}
 
 ?>
---EXPECTREGEX--
-Warning\: func_get_args\(\)\:  Called from the global scope - no function context in \S* on line 3
-bool\(false\)
+--EXPECT--
+func_get_args() cannot be called from the global scope