Skip to content

Commit a3b0fa0

Browse files
committed
Merge branch 'master' of https://git.php.net/repository/php-src
# By Adam Harvey (2) and others # Via Adam Harvey (2) and others * 'master' of https://git.php.net/repository/php-src: Implement variadic function syntax Added function opcache_compile_file() to load PHP scripts into cache without execution. Fixed issue #135 (segfault in interned strings if initial memory is too low) Fix typo: HTTP_ROW_POST_DATA → HTTP_RAW_POST_DATA. Make message and format arguments const char * to avoid build warning about invalid cast. Copy dba_*() keys before converting to string.
2 parents c175617 + 0d7a638 commit a3b0fa0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+3033
-2298
lines changed

NEWS

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ PHP NEWS
1414
. Reduced POST data memory usage by 200-300%. Removed INI setting
1515
always_populate_raw_post_data and the $HTTP_RAW_POST_DATA global
1616
variable. (Mike)
17+
. Implemented dedicated syntax for variadic functions
18+
(RFC: https://wiki.php.net/rfc/variadics). (Nikita)
1719

1820
- cURL:
1921
. Implemented FR #65646 (re-enable CURLOPT_FOLLOWLOCATION with open_basedir

UPGRADING

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,16 +26,18 @@ PHP X.Y UPGRADE NOTES
2626
<?php
2727
global $HTTP_RAW_POST_DATA;
2828
if (!isset($HTTP_RAW_POST_DATA)) {
29-
$HTTP_ROW_POST_DATA = file_get_contents("php://input");
29+
$HTTP_RAW_POST_DATA = file_get_contents("php://input");
3030
}
3131
?>
3232

3333
========================================
3434
2. New Features
3535
========================================
3636

37-
- Core:
38-
The php://input stream is now re-usable and can be used concurrently with
37+
- Added dedicated syntax for variadic functions.
38+
(https://wiki.php.net/rfc/variadics)
39+
40+
- The php://input stream is now re-usable and can be used concurrently with
3941
enable_post_data_reading=0.
4042

4143
========================================

UPGRADING.INTERNALS

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ UPGRADE NOTES - PHP X.Y
66
a. Addition of do_operation and compare object handlers
77
b. return_value_ptr now always available, RETVAL_ZVAL_FAST macros
88
c. POST data handling
9+
d. Arginfo changes
910

1011
2. Build system changes
1112
a. Unix build system changes
@@ -68,6 +69,47 @@ UPGRADE NOTES - PHP X.Y
6869
The recommended way to access raw POST data is to open and use a php://input
6970
stream wrapper. It is safe to be used concurrently and more than once.
7071

72+
d. Arginfo changes
73+
74+
The pass_rest_by_reference argument of the ZEND_BEGIN_ARG_INFO and
75+
ZEND_BEGIN_ARG_INFO_EX() is no longer used. The value passed to it is ignored.
76+
77+
Instead a variadic argument is created using ZEND_ARG_VARIADIC_INFO():
78+
79+
ZEND_ARG_VARIADIC_INFO(0, name) /* pass rest by value */
80+
ZEND_ARG_VARIADIC_INFO(1, name) /* pass rest by reference */
81+
ZEND_ARG_VARIADIC_INFO(ZEND_SEND_PREFER_REF, name)
82+
/* pass rest by prefer-ref */
83+
84+
ZEND_ARG_VARIADIC_INFO() should only be used for the last argument.
85+
86+
The following changes were applied to the zend_arg_info struct:
87+
88+
typedef struct _zend_arg_info {
89+
const char *class_name;
90+
zend_uint class_name_len;
91+
zend_uchar type_hint;
92+
+ zend_uchar pass_by_reference;
93+
zend_bool allow_null;
94+
- zend_bool pass_by_reference;
95+
+ zend_bool is_variadic;
96+
} zend_arg_info;
97+
98+
The following changes were applied to the zend_internal_function_info struct:
99+
100+
typedef struct _zend_internal_function_info {
101+
zend_uint required_num_args;
102+
zend_uchar _type_hint;
103+
zend_bool return_reference;
104+
- zend_bool pass_rest_by_reference;
105+
+ zend_bool _allow_null;
106+
+ zend_bool _is_variadic;
107+
} zend_internal_function_info;
108+
109+
The CHECK_ARG_SEND_TYPE(), ARG_MUST_BE_SENT_BY_REF(),
110+
ARG_SHOULD_BE_SENT_BY_REF() and ARG_MAY_BE_SENT_BY_REF() macros now assume
111+
that the argument passed to them is a zend_function* and that it is non-NULL.
112+
71113
========================
72114
2. Build system changes
73115
========================
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
--TEST--
2+
It's possible to add additional optional arguments with matching signature
3+
--FILE--
4+
<?php
5+
6+
interface DB {
7+
public function query($query, string ...$params);
8+
}
9+
10+
class MySQL implements DB {
11+
public function query($query, string $extraParam = null, string ...$params) { }
12+
}
13+
14+
?>
15+
===DONE===
16+
--EXPECT--
17+
===DONE===
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
Additional optional parameters must have a matching prototype
3+
--FILE--
4+
<?php
5+
6+
interface DB {
7+
public function query($query, string ...$params);
8+
}
9+
10+
class MySQL implements DB {
11+
public function query($query, int $extraParam = null, string ...$params) { }
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Declaration of MySQL::query() must be compatible with DB::query($query, string ...$params) in %s on line %d

Zend/tests/variadic/basic.phpt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
--TEST--
2+
Basic variadic function
3+
--FILE--
4+
<?php
5+
6+
function test1(... $args) {
7+
var_dump($args);
8+
}
9+
10+
test1();
11+
test1(1);
12+
test1(1, 2, 3);
13+
14+
function test2($arg1, $arg2, ...$args) {
15+
var_dump($arg1, $arg2, $args);
16+
}
17+
18+
test2(1, 2);
19+
test2(1, 2, 3);
20+
test2(1, 2, 3, 4, 5);
21+
22+
?>
23+
--EXPECT--
24+
array(0) {
25+
}
26+
array(1) {
27+
[0]=>
28+
int(1)
29+
}
30+
array(3) {
31+
[0]=>
32+
int(1)
33+
[1]=>
34+
int(2)
35+
[2]=>
36+
int(3)
37+
}
38+
int(1)
39+
int(2)
40+
array(0) {
41+
}
42+
int(1)
43+
int(2)
44+
array(1) {
45+
[0]=>
46+
int(3)
47+
}
48+
int(1)
49+
int(2)
50+
array(3) {
51+
[0]=>
52+
int(3)
53+
[1]=>
54+
int(4)
55+
[2]=>
56+
int(5)
57+
}

Zend/tests/variadic/by_ref.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Variadic arguments with by-reference passing
3+
--FILE--
4+
<?php
5+
6+
function test(&... $args) {
7+
$i = 0;
8+
foreach ($args as &$arg) {
9+
$arg = $i++;
10+
}
11+
}
12+
13+
test();
14+
test($a);
15+
var_dump($a);
16+
test($b, $c, $d);
17+
var_dump($b, $c, $d);
18+
19+
?>
20+
--EXPECT--
21+
int(0)
22+
int(0)
23+
int(1)
24+
int(2)

Zend/tests/variadic/by_ref_error.phpt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--TEST--
2+
By-ref variadics enforce the reference
3+
--FILE--
4+
<?php
5+
6+
function test(&... $args) { }
7+
8+
test(1);
9+
10+
?>
11+
--EXPECTF--
12+
Fatal error: Only variables can be passed by reference in %s on line %d
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Variadic argument cannot have a default value
3+
--FILE--
4+
<?php
5+
6+
function test(...$args = 123) {}
7+
8+
?>
9+
--EXPECTF--
10+
Fatal error: Variadic parameter cannot have a default value in %s on line %d
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
--TEST--
2+
It's not possible to turn a variadic function into a non-variadic one
3+
--FILE--
4+
<?php
5+
6+
interface DB {
7+
public function query($query, ...$params);
8+
}
9+
10+
class MySQL implements DB {
11+
public function query($query, $params) { }
12+
}
13+
14+
?>
15+
--EXPECTF--
16+
Fatal error: Declaration of MySQL::query() must be compatible with DB::query($query, ...$params) in %s on line %d
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
--TEST--
2+
Only the last argument can be variadic
3+
--FILE--
4+
<?php
5+
6+
function test($foo, ...$bar, $baz) {}
7+
8+
?>
9+
--EXPECTF--
10+
Fatal error: Only the last parameter can be variadic in %s on line %d
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
--TEST--
2+
Optional parameter before variadic parameter
3+
--FILE--
4+
<?php
5+
6+
function fn($reqParam, $optParam = null, ...$params) {
7+
var_dump($reqParam, $optParam, $params);
8+
}
9+
10+
fn(1);
11+
fn(1, 2);
12+
fn(1, 2, 3);
13+
fn(1, 2, 3, 4);
14+
fn(1, 2, 3, 4, 5);
15+
16+
?>
17+
--EXPECT--
18+
int(1)
19+
NULL
20+
array(0) {
21+
}
22+
int(1)
23+
int(2)
24+
array(0) {
25+
}
26+
int(1)
27+
int(2)
28+
array(1) {
29+
[0]=>
30+
int(3)
31+
}
32+
int(1)
33+
int(2)
34+
array(2) {
35+
[0]=>
36+
int(3)
37+
[1]=>
38+
int(4)
39+
}
40+
int(1)
41+
int(2)
42+
array(3) {
43+
[0]=>
44+
int(3)
45+
[1]=>
46+
int(4)
47+
[2]=>
48+
int(5)
49+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
--TEST--
2+
It's not possible to remove required parameter before a variadic parameter
3+
--FILE--
4+
<?php
5+
6+
/* Theoretically this should be valid because it weakens the constraint, but
7+
* PHP does not allow this (for non-variadics), so I'm not allowing it here, too,
8+
* to stay consistent. */
9+
10+
interface DB {
11+
public function query($query, ...$params);
12+
}
13+
14+
class MySQL implements DB {
15+
public function query(...$params) { }
16+
}
17+
18+
?>
19+
--EXPECTF--
20+
Fatal error: Declaration of MySQL::query() must be compatible with DB::query($query, ...$params) in %s on line %d
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
--TEST--
2+
Variadic arguments enforce typehints
3+
--FILE--
4+
<?php
5+
6+
function test(array... $args) {
7+
var_dump($args);
8+
}
9+
10+
test();
11+
test([0], [1], [2]);
12+
test([0], [1], 2);
13+
14+
?>
15+
--EXPECTF--
16+
array(0) {
17+
}
18+
array(3) {
19+
[0]=>
20+
array(1) {
21+
[0]=>
22+
int(0)
23+
}
24+
[1]=>
25+
array(1) {
26+
[0]=>
27+
int(1)
28+
}
29+
[2]=>
30+
array(1) {
31+
[0]=>
32+
int(2)
33+
}
34+
}
35+
36+
Catchable fatal error: Argument 3 passed to test() must be of the type array, integer given, called in %s on line %d
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
--TEST--
2+
Error suppression for typehints on variadic arguments works
3+
--FILE--
4+
<?php
5+
6+
function test(array... $args) {
7+
var_dump($args);
8+
}
9+
10+
set_error_handler(function($errno, $errstr) {
11+
var_dump($errstr);
12+
return true;
13+
});
14+
15+
test([0], [1], 2);
16+
17+
?>
18+
--EXPECTF--
19+
string(%d) "Argument 3 passed to test() must be of the type array, integer given, called in %s on line %d and defined"
20+
array(3) {
21+
[0]=>
22+
array(1) {
23+
[0]=>
24+
int(0)
25+
}
26+
[1]=>
27+
array(1) {
28+
[0]=>
29+
int(1)
30+
}
31+
[2]=>
32+
int(2)
33+
}

0 commit comments

Comments
 (0)