Skip to content

Commit

Permalink
Cleanup argument handling of Zend functions and methods
Browse files Browse the repository at this point in the history
  • Loading branch information
kocsismate committed Jul 12, 2020
1 parent 1c967df commit 1555411
Show file tree
Hide file tree
Showing 26 changed files with 221 additions and 171 deletions.
15 changes: 9 additions & 6 deletions Zend/tests/001.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,23 @@ class test {
}

test::test1(1);
var_dump(func_num_args());

try {
func_num_args();
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

echo "Done\n";
?>
--EXPECTF--
int(0)
int(1)
Exception: Too few arguments to function test2(), 0 passed in %s001.php on line 18 and exactly 1 expected
Exception: Too few arguments to function test2(), 0 passed in %s on line %d and exactly 1 expected
int(2)
int(0)
Exception: Too few arguments to function test3(), 1 passed in %s001.php on line 27 and exactly 2 expected
Exception: Too few arguments to function test3(), 1 passed in %s on line %d and exactly 2 expected
int(2)
int(1)

Warning: func_num_args(): Called from the global scope - no function context in %s on line %d
int(-1)
func_num_args() must be called from a function context
Done
24 changes: 12 additions & 12 deletions Zend/tests/002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -96,26 +96,26 @@ try {
echo "Done\n";
?>
--EXPECTF--
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
func_get_arg(): Argument #1 ($argument_number) must be greater than or equal to 0
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
func_get_arg(): Argument #1 ($argument_number) must be greater than or equal to 0
int(10)
func_get_arg(): Argument 1 not passed to function
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
int(1)
func_get_arg(): Argument 1 not passed to function
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
Exception: Too few arguments to function test2(), 0 passed in %s002.php on line %d and exactly 1 expected
int(1)
int(2)
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
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
func_get_arg(): Argument #1 ($argument_number) must be greater than or equal to 0
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
Exception: Too few arguments to function test3(), 1 passed in %s on line %d and exactly 2 expected
int(1)
int(2)
func_get_arg(): Argument 2 not passed to function
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
int(1)
func_get_arg(): Argument 1 not passed to function
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
func_get_arg() cannot be called from the global scope
Done
2 changes: 1 addition & 1 deletion Zend/tests/004.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ var_dump(strncmp("qwerty", "qwerty123", 7));
?>
--EXPECT--
int(0)
strncmp(): Argument #3 ($len) must be greater than or equal to 0
strncmp(): Argument #3 ($length) must be greater than or equal to 0
int(0)
int(0)
int(-1)
2 changes: 1 addition & 1 deletion Zend/tests/006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ var_dump(strncasecmp("01", "01", 1000));

?>
--EXPECT--
strncasecmp(): Argument #3 ($len) must be greater than or equal to 0
strncasecmp(): Argument #3 ($length) must be greater than or equal to 0
int(0)
int(-3)
int(0)
Expand Down
9 changes: 6 additions & 3 deletions Zend/tests/008.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,12 @@ var_dump(define("test const", 3));
var_dump(define("test const", 3));
var_dump(define("test", array(1)));
var_dump(define("test1", fopen(__FILE__, 'r')));

try {
var_dump(define("test2", new stdclass));
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
}

var_dump(constant(" "));
var_dump(constant("[[["));
Expand All @@ -37,9 +42,7 @@ Notice: Constant test const already defined in %s on line %d
bool(false)
bool(true)
bool(true)

Warning: Constants may only evaluate to scalar values, arrays or resources in %s on line %d
bool(false)
define(): Argument #2 ($value) must be of type bool|int|float|string|array|resource|null, stdClass given
int(1)
int(2)
int(3)
Expand Down
2 changes: 1 addition & 1 deletion Zend/tests/020.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ try {
?>
--EXPECT--
func_get_arg() cannot be called from the global scope
func_get_arg(): Argument 1 not passed to function
func_get_arg(): Argument #1 ($argument_number) must be less than the number of the arguments passed to the currently executed function
28 changes: 16 additions & 12 deletions Zend/tests/bug37811.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,23 @@ class TestClass
}
}

define("Bar",new TestClass);
define("Bar", new TestClass);
var_dump(Bar);
define("Baz",new stdClass);
var_dump(Baz);

?>
===DONE===
--EXPECTF--
string(3) "Foo"
try {
define("Baz", new stdClass);
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
}

Warning: Constants may only evaluate to scalar values, arrays or resources in %sbug37811.php on line %d
try {
var_dump(Baz);
} catch (Error $exception) {
echo $exception->getMessage() . "\n";
}

Fatal error: Uncaught Error: Undefined constant "Baz" in %s:%d
Stack trace:
#0 {main}
thrown in %s on line %d
?>
--EXPECT--
string(3) "Foo"
define(): Argument #2 ($value) must be of type bool|int|float|string|array|resource|null, stdClass given
Undefined constant "Baz"
22 changes: 16 additions & 6 deletions Zend/tests/bug44827.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@
Bug #44827 (define() allows :: in constant names)
--FILE--
<?php
define('foo::bar', 1);
define('::', 1);
?>
--EXPECTF--
Warning: Class constants cannot be defined or redefined in %sbug44827.php on line %d

Warning: Class constants cannot be defined or redefined in %sbug44827.php on line %d
try {
define('foo::bar', 1);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

try {
define('::', 1);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

?>
--EXPECT--
define(): Argument #1 ($constant_name) cannot be a class constant
define(): Argument #1 ($constant_name) cannot be a class constant
15 changes: 8 additions & 7 deletions Zend/tests/bug72162.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,12 @@ Bug #72162 (use-after-free - error_reporting)
<?php
error_reporting(E_ALL);
$var11 = new StdClass();
$var16 = error_reporting($var11);

try {
$var16 = error_reporting($var11);
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
}
?>
--EXPECTF--
Fatal error: Uncaught Error: Object of class stdClass could not be converted to string in %s:%d
Stack trace:
#0 %s(%d): error_reporting(Object(stdClass))
#1 {main}
thrown in %s on line %d
--EXPECT--
error_reporting(): Argument #1 ($error_level) must be of type ?int, stdClass given
10 changes: 7 additions & 3 deletions Zend/tests/class_alias_006.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@ Testing creation of alias to an internal class
--FILE--
<?php

class_alias('stdclass', 'foo');
try {
class_alias('stdclass', 'foo');
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}

?>
--EXPECTF--
Warning: First argument of class_alias() must be a name of user defined class in %s on line %d
--EXPECT--
class_alias(): Argument #1 ($original_class_name) must be a user-defined class name, internal class name given
1 change: 1 addition & 0 deletions Zend/tests/closure_040.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ $ca = $a->getIncrementor();
$cas = $a->getStaticIncrementor();

$ca->bindTo($a, array());

$cas->bindTo($a, 'A');

?>
Expand Down
21 changes: 13 additions & 8 deletions Zend/tests/constant_arrays.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,21 @@ $y[0] = 3;
var_dump($x, $y, QUX);

// ensure objects not allowed in arrays
var_dump(define('ELEPHPANT', [new StdClass]));
try {
define('ELEPHPANT', [new StdClass]);
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
}

// ensure recursion doesn't crash
$recursive = [];
$recursive[0] = &$recursive;
var_dump(define('RECURSION', $recursive));

try {
define('RECURSION', $recursive);
} catch (ValueError $exception) {
echo $exception->getMessage() . "\n";
}
--EXPECTF--
array(4) {
[0]=>
Expand Down Expand Up @@ -92,9 +101,5 @@ array(1) {
[0]=>
int(7)
}

Warning: Constants may only evaluate to scalar values, arrays or resources in %s on line %d
bool(false)

Warning: Constants cannot be recursive arrays in %s on line %d
bool(false)
define(): Argument #2 ($value) must be of type bool|int|float|string|array|resource|null, stdClass given
define(): Argument #2 ($value) cannot be a recursive array
11 changes: 8 additions & 3 deletions Zend/tests/constants_002.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,12 @@ Defining constants with non-scalar values
--FILE--
<?php

define('foo', new stdClass);
try {
define('foo', new stdClass);
} catch (TypeError $exception) {
echo $exception->getMessage() . "\n";
}

try {
var_dump(foo);
} catch (Error $e) {
Expand All @@ -14,7 +19,7 @@ define('foo', fopen(__FILE__, 'r'));
var_dump(foo);

?>
--EXPECTF--
Warning: Constants may only evaluate to scalar values, arrays or resources in %s on line %d
--EXPECT--
define(): Argument #2 ($value) must be of type bool|int|float|string|array|resource|null, stdClass given
Undefined constant "foo"
resource(5) of type (stream)
Loading

0 comments on commit 1555411

Please sign in to comment.