Skip to content

Commit aff3821

Browse files
committed
Merge remote-tracking branch 'upstream/master' into array_function_stubs
2 parents 0daf2c8 + c53064f commit aff3821

Some content is hidden

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

42 files changed

+430
-547
lines changed

Zend/tests/grammar/bug78441.phpt

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
--TEST--
2+
Bug #78441 (Parse error due to heredoc identifier followed by digit)
3+
--FILE--
4+
<?php
5+
echo <<<FOO
6+
FOO4
7+
FOO, PHP_EOL;
8+
9+
echo <<<FOO
10+
bar
11+
FOO4
12+
FOO, PHP_EOL;
13+
14+
echo <<<'FOO'
15+
bar
16+
FOO4
17+
FOO, PHP_EOL;
18+
?>
19+
--EXPECT--
20+
FOO4
21+
bar
22+
FOO4
23+
bar
24+
FOO4

Zend/zend_language_scanner.l

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,7 @@ do { \
113113
#define GET_DOUBLE_QUOTES_SCANNED_LENGTH() SCNG(scanned_string_len)
114114

115115
#define IS_LABEL_START(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z') || (c) == '_' || (c) >= 0x80)
116+
#define IS_LABEL_SUCCESSOR(c) (((c) >= 'a' && (c) <= 'z') || ((c) >= 'A' && (c) <= 'Z') || ((c) >= '0' && (c) <= '9') || (c) == '_' || (c) >= 0x80)
116117

117118
#define ZEND_IS_OCT(c) ((c)>='0' && (c)<='7')
118119
#define ZEND_IS_HEX(c) (((c)>='0' && (c)<='9') || ((c)>='a' && (c)<='f') || ((c)>='A' && (c)<='F'))
@@ -2419,7 +2420,7 @@ skip_escape_conversion:
24192420
24202421
/* Check for ending label on the next line */
24212422
if (heredoc_label->length < YYLIMIT - YYCURSOR && !memcmp(YYCURSOR, s, heredoc_label->length)) {
2422-
if (!IS_LABEL_START(YYCURSOR[heredoc_label->length])) {
2423+
if (!IS_LABEL_SUCCESSOR(YYCURSOR[heredoc_label->length])) {
24232424
if (spacing == (HEREDOC_USING_SPACES | HEREDOC_USING_TABS)) {
24242425
zend_throw_exception(zend_ce_parse_error, "Invalid indentation - tabs and spaces cannot be mixed", 0);
24252426
}
@@ -2676,7 +2677,7 @@ double_quotes_scan_done:
26762677
26772678
/* Check for ending label on the next line */
26782679
if (IS_LABEL_START(*YYCURSOR) && heredoc_label->length < YYLIMIT - YYCURSOR && !memcmp(YYCURSOR, heredoc_label->label, heredoc_label->length)) {
2679-
if (IS_LABEL_START(YYCURSOR[heredoc_label->length])) {
2680+
if (IS_LABEL_SUCCESSOR(YYCURSOR[heredoc_label->length])) {
26802681
continue;
26812682
}
26822683
@@ -2797,7 +2798,7 @@ heredoc_scan_done:
27972798
27982799
/* Check for ending label on the next line */
27992800
if (IS_LABEL_START(*YYCURSOR) && heredoc_label->length < YYLIMIT - YYCURSOR && !memcmp(YYCURSOR, heredoc_label->label, heredoc_label->length)) {
2800-
if (IS_LABEL_START(YYCURSOR[heredoc_label->length])) {
2801+
if (IS_LABEL_SUCCESSOR(YYCURSOR[heredoc_label->length])) {
28012802
continue;
28022803
}
28032804

ext/standard/array.c

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2704,8 +2704,9 @@ PHP_FUNCTION(array_fill_keys)
27042704
#define RANGE_CHECK_DOUBLE_INIT_ARRAY(start, end) do { \
27052705
double __calc_size = ((start - end) / step) + 1; \
27062706
if (__calc_size >= (double)HT_MAX_SIZE) { \
2707-
php_error_docref(NULL, E_WARNING, "The supplied range exceeds the maximum array size: start=%0.0f end=%0.0f", end, start); \
2708-
RETURN_FALSE; \
2707+
zend_throw_error(NULL, \
2708+
"The supplied range exceeds the maximum array size: start=%0.0f end=%0.0f", end, start); \
2709+
return; \
27092710
} \
27102711
size = (uint32_t)_php_math_round(__calc_size, 0, PHP_ROUND_HALF_UP); \
27112712
array_init_size(return_value, size); \
@@ -2715,15 +2716,16 @@ PHP_FUNCTION(array_fill_keys)
27152716
#define RANGE_CHECK_LONG_INIT_ARRAY(start, end) do { \
27162717
zend_ulong __calc_size = ((zend_ulong) start - end) / lstep; \
27172718
if (__calc_size >= HT_MAX_SIZE - 1) { \
2718-
php_error_docref(NULL, E_WARNING, "The supplied range exceeds the maximum array size: start=" ZEND_LONG_FMT " end=" ZEND_LONG_FMT, end, start); \
2719-
RETURN_FALSE; \
2719+
zend_throw_error(NULL, \
2720+
"The supplied range exceeds the maximum array size: start=" ZEND_LONG_FMT " end=" ZEND_LONG_FMT, end, start); \
2721+
return; \
27202722
} \
27212723
size = (uint32_t)(__calc_size + 1); \
27222724
array_init_size(return_value, size); \
27232725
zend_hash_real_init_packed(Z_ARRVAL_P(return_value)); \
27242726
} while (0)
27252727

2726-
/* {{{ proto array|false range(mixed low, mixed high[, int step])
2728+
/* {{{ proto array range(mixed low, mixed high[, int step])
27272729
Create an array containing the range of integers or characters from low to high (inclusive) */
27282730
PHP_FUNCTION(range)
27292731
{
@@ -2812,8 +2814,8 @@ PHP_FUNCTION(range)
28122814
high = zval_get_double(zhigh);
28132815

28142816
if (zend_isinf(high) || zend_isinf(low)) {
2815-
php_error_docref(NULL, E_WARNING, "Invalid range supplied: start=%0.0f end=%0.0f", low, high);
2816-
RETURN_FALSE;
2817+
zend_throw_error(NULL, "Invalid range supplied: start=%0.0f end=%0.0f", low, high);
2818+
return;
28172819
}
28182820

28192821
if (low > high) { /* Negative steps */
@@ -2905,8 +2907,8 @@ PHP_FUNCTION(range)
29052907
}
29062908
err:
29072909
if (err) {
2908-
php_error_docref(NULL, E_WARNING, "step exceeds the specified range");
2909-
RETURN_FALSE;
2910+
zend_throw_error(NULL, "step exceeds the specified range");
2911+
return;
29102912
}
29112913
}
29122914
/* }}} */
@@ -5611,7 +5613,7 @@ PHPAPI int php_multisort_compare(const void *a, const void *b) /* {{{ */
56115613
#define MULTISORT_ABORT \
56125614
efree(func); \
56135615
efree(arrays); \
5614-
RETURN_FALSE;
5616+
return;
56155617

56165618
static void array_bucket_p_sawp(void *p, void *q) /* {{{ */ {
56175619
Bucket *t;
@@ -5688,7 +5690,7 @@ PHP_FUNCTION(array_multisort)
56885690
sort_order = Z_LVAL_P(arg) == PHP_SORT_DESC ? PHP_SORT_DESC : PHP_SORT_ASC;
56895691
parse_state[MULTISORT_ORDER] = 0;
56905692
} else {
5691-
php_error_docref(NULL, E_WARNING, "Argument #%d is expected to be an array or sorting flag that has not already been specified", i + 1);
5693+
zend_type_error("Argument #%d is expected to be an array or sorting flag that has not already been specified", i + 1);
56925694
MULTISORT_ABORT;
56935695
}
56945696
break;
@@ -5704,19 +5706,19 @@ PHP_FUNCTION(array_multisort)
57045706
sort_type = (int)Z_LVAL_P(arg);
57055707
parse_state[MULTISORT_TYPE] = 0;
57065708
} else {
5707-
php_error_docref(NULL, E_WARNING, "Argument #%d is expected to be an array or sorting flag that has not already been specified", i + 1);
5709+
zend_type_error("Argument #%d is expected to be an array or sorting flag that has not already been specified", i + 1);
57085710
MULTISORT_ABORT;
57095711
}
57105712
break;
57115713

57125714
default:
5713-
php_error_docref(NULL, E_WARNING, "Argument #%d is an unknown sort flag", i + 1);
5715+
zend_type_error("Argument #%d is an unknown sort flag", i + 1);
57145716
MULTISORT_ABORT;
57155717
break;
57165718

57175719
}
57185720
} else {
5719-
php_error_docref(NULL, E_WARNING, "Argument #%d is expected to be an array or a sort flag", i + 1);
5721+
zend_type_error("Argument #%d is expected to be an array or a sort flag", i + 1);
57205722
MULTISORT_ABORT;
57215723
}
57225724
}
@@ -5727,7 +5729,7 @@ PHP_FUNCTION(array_multisort)
57275729
array_size = zend_hash_num_elements(Z_ARRVAL_P(arrays[0]));
57285730
for (i = 0; i < num_arrays; i++) {
57295731
if (zend_hash_num_elements(Z_ARRVAL_P(arrays[i])) != (uint32_t)array_size) {
5730-
php_error_docref(NULL, E_WARNING, "Array sizes are inconsistent");
5732+
zend_throw_error(NULL, "Array sizes are inconsistent");
57315733
MULTISORT_ABORT;
57325734
}
57335735
}
@@ -6354,7 +6356,7 @@ PHP_FUNCTION(array_chunk)
63546356

63556357
/* Do bounds checking for size parameter. */
63566358
if (size < 1) {
6357-
php_error_docref(NULL, E_WARNING, "Size parameter expected to be greater than 0");
6359+
zend_throw_error(NULL, "Size parameter expected to be greater than 0");
63586360
return;
63596361
}
63606362

@@ -6401,7 +6403,7 @@ PHP_FUNCTION(array_chunk)
64016403
}
64026404
/* }}} */
64036405

6404-
/* {{{ proto array|false array_combine(array keys, array values)
6406+
/* {{{ proto array array_combine(array keys, array values)
64056407
Creates an array by using the elements of the first parameter as keys and the elements of the second as the corresponding values */
64066408
PHP_FUNCTION(array_combine)
64076409
{
@@ -6419,8 +6421,8 @@ PHP_FUNCTION(array_combine)
64196421
num_values = zend_hash_num_elements(values);
64206422

64216423
if (num_keys != num_values) {
6422-
php_error_docref(NULL, E_WARNING, "Both parameters should have an equal number of elements");
6423-
RETURN_FALSE;
6424+
zend_throw_error(NULL, "Both parameters should have an equal number of elements");
6425+
return;
64246426
}
64256427

64266428
if (!num_keys) {

ext/standard/tests/array/array_chunk.phpt

Lines changed: 0 additions & 21 deletions
This file was deleted.

ext/standard/tests/array/array_chunk2.phpt

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,29 @@ basic array_chunk test
33
--FILE--
44
<?php
55
$input_array = array('a', 'b', 'c', 'd', 'e');
6-
var_dump(array_chunk($input_array, 0));
7-
var_dump(array_chunk($input_array, 0, true));
6+
7+
try {
8+
var_dump(array_chunk($input_array, 0));
9+
} catch (\Error $e) {
10+
echo $e->getMessage() . "\n";
11+
}
12+
13+
try {
14+
var_dump(array_chunk($input_array, 0, true));
15+
} catch (\Error $e) {
16+
echo $e->getMessage() . "\n";
17+
}
18+
819
var_dump(array_chunk($input_array, 1));
920
var_dump(array_chunk($input_array, 1, true));
1021
var_dump(array_chunk($input_array, 2));
1122
var_dump(array_chunk($input_array, 2, true));
1223
var_dump(array_chunk($input_array, 10));
1324
var_dump(array_chunk($input_array, 10, true));
1425
?>
15-
--EXPECTF--
16-
Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
17-
NULL
18-
19-
Warning: array_chunk(): Size parameter expected to be greater than 0 in %s on line %d
20-
NULL
26+
--EXPECT--
27+
Size parameter expected to be greater than 0
28+
Size parameter expected to be greater than 0
2129
array(5) {
2230
[0]=>
2331
array(1) {

ext/standard/tests/array/array_chunk_variation10.phpt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ array_chunk() - variation 10
44
<?php
55
$array = array (1 => 1, 2 => 2, 3 => 3);
66
var_dump ($array);
7-
for ($i = 0; $i < (sizeof($array) + 1); $i++) {
7+
for ($i = 1; $i < (sizeof($array) + 1); $i++) {
88
echo "[$i]\n";
9-
var_dump (@array_chunk ($array, $i));
10-
var_dump (@array_chunk ($array, $i, TRUE));
11-
var_dump (@array_chunk ($array, $i, FALSE));
9+
var_dump (array_chunk ($array, $i));
10+
var_dump (array_chunk ($array, $i, TRUE));
11+
var_dump (array_chunk ($array, $i, FALSE));
1212
echo "\n";
1313
}
1414
?>
@@ -21,11 +21,6 @@ array(3) {
2121
[3]=>
2222
int(3)
2323
}
24-
[0]
25-
NULL
26-
NULL
27-
NULL
28-
2924
[1]
3025
array(3) {
3126
[0]=>

ext/standard/tests/array/array_chunk_variation11.phpt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,11 @@ array_chunk() - variation 11
55
$array = array (0 => 0, 3 => 2);
66

77
var_dump ($array);
8-
for ($i = 0; $i < (sizeof($array) + 1); $i++) {
8+
for ($i = 1; $i < (sizeof($array) + 1); $i++) {
99
echo "[$i]\n";
10-
var_dump (@array_chunk ($array, $i));
11-
var_dump (@array_chunk ($array, $i, TRUE));
12-
var_dump (@array_chunk ($array, $i, FALSE));
10+
var_dump (array_chunk ($array, $i));
11+
var_dump (array_chunk ($array, $i, TRUE));
12+
var_dump (array_chunk ($array, $i, FALSE));
1313
echo "\n";
1414
}
1515
?>
@@ -20,11 +20,6 @@ array(2) {
2020
[3]=>
2121
int(2)
2222
}
23-
[0]
24-
NULL
25-
NULL
26-
NULL
27-
2823
[1]
2924
array(2) {
3025
[0]=>

ext/standard/tests/array/array_chunk_variation12.phpt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ array_chunk() - variation 12
44
<?php
55
$array = array (1 => 1, 5 => 2, 8 => 3);
66
var_dump ($array);
7-
for ($i = 0; $i < (sizeof($array) + 1); $i++) {
7+
for ($i = 1; $i < (sizeof($array) + 1); $i++) {
88
echo "[$i]\n";
9-
var_dump (@array_chunk ($array, $i));
10-
var_dump (@array_chunk ($array, $i, TRUE));
11-
var_dump (@array_chunk ($array, $i, FALSE));
9+
var_dump (array_chunk ($array, $i));
10+
var_dump (array_chunk ($array, $i, TRUE));
11+
var_dump (array_chunk ($array, $i, FALSE));
1212
echo "\n";
1313
}
1414
?>
@@ -21,11 +21,6 @@ array(3) {
2121
[8]=>
2222
int(3)
2323
}
24-
[0]
25-
NULL
26-
NULL
27-
NULL
28-
2924
[1]
3025
array(3) {
3126
[0]=>

ext/standard/tests/array/array_chunk_variation13.phpt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ array_chunk() - variation 13
44
<?php
55
$array = array (1, 2);
66
var_dump ($array);
7-
for ($i = 0; $i < (sizeof($array) + 1); $i++) {
7+
for ($i = 1; $i < (sizeof($array) + 1); $i++) {
88
echo "[$i]\n";
9-
var_dump (@array_chunk ($array, $i));
10-
var_dump (@array_chunk ($array, $i, TRUE));
11-
var_dump (@array_chunk ($array, $i, FALSE));
9+
var_dump (array_chunk ($array, $i));
10+
var_dump (array_chunk ($array, $i, TRUE));
11+
var_dump (array_chunk ($array, $i, FALSE));
1212
echo "\n";
1313
}
1414
?>
@@ -19,11 +19,6 @@ array(2) {
1919
[1]=>
2020
int(2)
2121
}
22-
[0]
23-
NULL
24-
NULL
25-
NULL
26-
2722
[1]
2823
array(2) {
2924
[0]=>

ext/standard/tests/array/array_chunk_variation14.phpt

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,11 @@ array_chunk() - variation 14
44
<?php
55
$array = array (0, 1, 2);
66
var_dump ($array);
7-
for ($i = 0; $i < (sizeof($array) + 1); $i++) {
7+
for ($i = 1; $i < (sizeof($array) + 1); $i++) {
88
echo "[$i]\n";
9-
var_dump (@array_chunk ($array, $i));
10-
var_dump (@array_chunk ($array, $i, TRUE));
11-
var_dump (@array_chunk ($array, $i, FALSE));
9+
var_dump (array_chunk ($array, $i));
10+
var_dump (array_chunk ($array, $i, TRUE));
11+
var_dump (array_chunk ($array, $i, FALSE));
1212
echo "\n";
1313
}
1414
?>
@@ -21,11 +21,6 @@ array(3) {
2121
[2]=>
2222
int(2)
2323
}
24-
[0]
25-
NULL
26-
NULL
27-
NULL
28-
2924
[1]
3025
array(3) {
3126
[0]=>

0 commit comments

Comments
 (0)