Skip to content

Promote some warnings to Errors in Zend basic functions #5325

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 70 additions & 50 deletions Zend/tests/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this zero-indexing how it seems? 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, because the argument list starts from 0 for func_get_arg() kinda odd but it's documented.

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
13 changes: 7 additions & 6 deletions Zend/tests/003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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
14 changes: 7 additions & 7 deletions Zend/tests/004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
14 changes: 8 additions & 6 deletions Zend/tests/006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -12,16 +17,13 @@ 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)
int(0)
int(2)
int(0)
int(0)
Done
47 changes: 32 additions & 15 deletions Zend/tests/011.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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
24 changes: 14 additions & 10 deletions Zend/tests/015.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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
23 changes: 13 additions & 10 deletions Zend/tests/020.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -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));
Expand All @@ -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
Loading