1
0
mirror of https://github.com/php/php-src.git synced 2026-03-25 08:42:29 +01:00
Commit Graph

808 Commits

Author SHA1 Message Date
divinity76
47e440019c improve range array overflow error message (#16510)
Improve range array overflow error message

Added info about "how much it exceeded" and the maximum allowable array size.

Makes debugging easier when encountering this specific issue.
2024-12-30 18:53:16 +01:00
Niels Dossche
563da1b9d2 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-16957: Assertion failure in array_shift with self-referencing array
2024-11-29 19:22:07 +01:00
Niels Dossche
ab7c3b1e7b Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16957: Assertion failure in array_shift with self-referencing array
2024-11-29 19:21:49 +01:00
Niels Dossche
f1fc4e8ff7 Fix GH-16957: Assertion failure in array_shift with self-referencing array
We have an RC1 violation because we're immediately dereferencing and
copying the resulting array in the test case. Instead, transfer the
lifetime using RETVAL_COPY_VALUE and unwrap only after the internal
iterator is reset.

Closes GH-16970.
2024-11-29 19:21:11 +01:00
Niels Dossche
c10f5ce9c1 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-16905: Internal iterator functions can't handle UNDEF properties
2024-11-28 19:23:02 +01:00
Niels Dossche
3a80936391 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix GH-16905: Internal iterator functions can't handle UNDEF properties
2024-11-28 19:22:55 +01:00
Niels Dossche
6a195bd9e7 Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix GH-16905: Internal iterator functions can't handle UNDEF properties
2024-11-28 19:22:36 +01:00
Niels Dossche
e1b4534790 Fix GH-16905: Internal iterator functions can't handle UNDEF properties
Closes GH-16907.
2024-11-28 19:22:10 +01:00
Gina Peter Banyard
f3b150a6a6 ext/standard: Move array_walk(_recursive)() tests into subfolder 2024-11-08 07:04:00 +00:00
Gina Peter Banyard
f011684206 ext/standard: Split sort tests that contain escape sequences 2024-11-08 07:04:00 +00:00
Gina Peter Banyard
d8a63a38c6 ext/standard: Move sort() related tests into subfolder 2024-11-08 07:04:00 +00:00
Arnaud Le Blanc
3952a8f9f1 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  [ci skip] NEWS for GH-16061
  Fix array_merge_recursive(): convert_to_array() may need separation (#16061)
2024-10-02 12:44:00 +02:00
Arnaud Le Blanc
220c8828cc Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  [ci skip] NEWS for GH-16061
  Fix array_merge_recursive(): convert_to_array() may need separation (#16061)
2024-10-02 12:43:48 +02:00
Arnaud Le Blanc
545bef8ae6 Fix array_merge_recursive(): convert_to_array() may need separation (#16061) 2024-10-02 12:37:04 +02:00
Niels Dossche
27b3131422 Fix GH-15982: Assertion failure with array_find when references are involved
Closes GH-15983.
2024-09-22 14:34:55 +02:00
Gina Peter Bnayard
5853cdb73d Use "must not" instead of "cannot" wording 2024-08-21 21:12:17 +01:00
Gina Peter Banyard
a79c70f574 [RFC] Convert exit (and die) from language constructs to functions (#13483)
RFC: https://wiki.php.net/rfc/exit-as-function
2024-08-14 12:44:12 +01:00
David Carlier
0410bf4147 Merge branch 'PHP-8.3' 2024-07-03 18:57:54 +01:00
David Carlier
15bea9ed74 Fix GH-14775: range overflow on negative step.
overflow occurs since we only deal with positive steps.

close GH-14778
2024-07-03 18:57:25 +01:00
Joshua Rüsweg
e4a8d5b16f RFC: array_find (#14108)
see https://wiki.php.net/rfc/array_find
2024-05-31 19:39:12 +02:00
Derick Rethans
412a3954b4 Merge branch 'PHP-8.3' 2024-05-20 15:51:19 +01:00
Derick Rethans
9c9f49a1f4 Merge branch 'PHP-8.2' into PHP-8.3 2024-05-20 15:49:46 +01:00
Saki Takamachi
0a8fbef996 Added test 2024-05-20 15:13:53 +01:00
Tim Düsterhus
08b2ab22f4 Include the source location in Closure names (#13550)
* Include the source location in Closure names

This change makes stack traces involving Closures, especially multiple
different Closures, much more useful, because it's more easily visible *which*
closure was called for a given stack frame.

The implementation is similar to that of anonymous classes which already
include the file name and line number within their generated classname.

* Update scripts/dev/bless_tests.php for closure naming

* Adjust existing tests for closure naming

* Adjust tests for closure naming that were not caught locally

* Drop the namespace from closure names

This is redundant with the included filename.

* Include filename and line number as separate keys in Closure debug info

* Fix test

* Fix test

* Include the surrounding class and function name in closure names

* Fix test

* Relax test expecations

* Fix tests after merge

* NEWS / UPGRADING
2024-04-12 18:21:13 +02:00
Niels Dossche
1d6f344bea Fix GH-13094: range(9.9, '0') causes segmentation fault
`start_type + end_type < 2*IS_STRING` is not right, in this test case
the types are start_type==5 (IS_DOUBLE), end_type==7 (IS_ARRAY).
The IS_ARRAY type is a sentinel to disambiguate single-byte strings.
The path must be taken when one of the types is not a string nor a
single-byte string. Therefore, use < IS_STRING with an OR condition.

Closes GH-13105.
2024-01-09 22:11:45 +01:00
Máté Kocsis
c322da0606 Fix misleading pass by reference error message (#10639) 2023-07-18 15:02:38 +02:00
Máté Kocsis
4acf0084dc Deprecate calling FFI::cast(), FFI::new(), and FFI::type() statically 2023-07-18 12:59:21 +02:00
George Peter Banyard
d8696f9216 [RFC] Path to Saner Increment/Decrement operators (#10358)
* Add behavioural tests for incdec operators

* Add support to ++/-- for objects castable to _IS_NUMBER

* Add str_increment() function

* Add str_decrement() function

RFC: https://wiki.php.net/rfc/saner-inc-dec-operators

Co-authored-by: Ilija Tovilo <ilija.tovilo@me.com>
Co-authored-by: Arnaud Le Blanc <arnaud.lb@gmail.com>
2023-07-17 15:51:24 +01:00
George Peter Banyard
798c40a739 [RFC] Define proper semantics for range() function (#10826)
RFC: https://wiki.php.net/rfc/proper-range-semantics
2023-06-19 14:25:26 +01:00
George Peter Banyard
53829b7daf Move range() tests to a dedicated folder 2023-06-18 13:08:50 +01:00
George Peter Banyard
99fa740acb Use common function for TypeError on illegal offset access (#10544)
This merges all usages of emitting an offset TypeError into a new ZEND_API function
zend_illegal_container_offset(const zend_string* container, const zval *offset, int type);

Where the container should represent the type on which the access is attempted (e.g. string, array)
The offset zval that is used, where the error message will display its type
The type of access, which should be a BP_VAR_* constant, to get special message for isset/empty/unset
2023-06-06 11:28:19 +01:00
George Peter Banyard
15402454a6 ext/standard/array.c: Optimize min/max functions for int/float (#11194)
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2023-06-02 10:27:46 +01:00
Julien Quiaios
bb38ad7768 Add new test for array_fill() to cover the case when the parameter count is too large (#11184) 2023-05-05 12:36:17 +01:00
ColinHDev
e2f477c2cb Fix negative indices on empty array not affecting next chosen index
Changed the value of nNextFreeElement in _zend_empty_array from 0 to
ZEND_LONG_MIN.

Fixes GH-11154
Closes GH-11157
2023-05-02 12:05:48 +02:00
George Peter Banyard
3b06618813 RFC: Saner array_(sum|product)() (#10161)
RFC: https://wiki.php.net/rfc/saner-array-sum-product

Moreover, the internal fast_add_function() function was removed.
2023-03-07 15:40:17 +00:00
Marcos Marcolin
641fe23e3a Improve illegal offset error messages (#10504)
Co-authored-by: Marcos Marcolin <marcos@ixcsoft.com.br>
2023-02-08 12:11:41 +00:00
Máté Kocsis
7936c8085e Fix GH-8329 Print true/false instead of bool in error and debug messages (#8385) 2023-01-23 10:52:14 +01:00
Niels
6ab503814d Make array_pad's $length warning less confusing (#10149)
Remove array_pad's arbitrary length restriction

The error message was wrong; it *is* possible to use a larger length.
Furthermore, there is an arbitrary restriction on the new array's
length.

Fix both by checking the length against HT_MAX_SIZE.
2023-01-14 12:15:56 +01:00
Christoph M. Becker
1094a859ad Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-9296: `ksort` behaves incorrectly on arrays with mixed keys
2022-08-12 11:38:21 +02:00
Christoph M. Becker
7908aae30c Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-9296: `ksort` behaves incorrectly on arrays with mixed keys
2022-08-12 11:36:24 +02:00
Denis Vaksman
cd1aed8edd Fix GH-9296: ksort behaves incorrectly on arrays with mixed keys
The comparator function used at ksort in SORT_REGULAR mode
need to be consistent with basic comparison rules. These rules
were changed in PHP-8.0 for numeric strings, but comparator
used at ksort kept the old behaviour. It leads to inconsistent
situations, when after ksort the first key is GREATER than some
of the next ones by according to the basic comparison operators.

Closes GH-9293.
2022-08-12 11:32:23 +02:00
Christoph M. Becker
ad04345eb3 Fix GH-9244: Segfault with array_multisort + array_shift
After restructuring non-packed arrays, we either need to pack them if
possible, or to rehash them.

Closes GH-9247.
2022-08-05 17:09:54 +02:00
Michael Voříšek
60189aa96a Skip locale tests /w musl libc (#9141) 2022-07-25 23:56:14 +01:00
Christoph M. Becker
a1b05a3a40 Tweak $count range check of array_fill()
We fix the `UNEXPECTED(EXPECTED(…))`, which does not make sense, and
replace the magic number with the respective macro.   We also add a
test case to verify the expected behavior for an `array_fill()` edge
case.

Closes GH-8804.
2022-06-21 11:39:05 +02:00
Marco Pivetta
25cb9cdb79 Fix GH-8232 - always reference classes in var_export() via their FQCN
Closes GH-8233

This fix corrects a behavior of `var_export()` that was mostly "hidden" until PHP 8.1 introduced:

* properties with object initializers
* constants containing object references
* default values of class properties containing `enum`s

Since `var_export(..., true)` is mostly used in conjunction with code generation,
and we cannot make assumptions about the generated code being placed in the root
namespace, we must always provide the FQCN of a class in exported code.

For example:

```php
<?php

namespace MyNamespace { class Foo {} }

namespace { echo "<?php\n\nnamespace Example;\n\n" . var_export(new \MyNamespace\Foo(), true) . ';'; }
```

produces:

```php
<?php

namespace Example;

MyNamespace\Foo::__set_state(array(
));
```

This code snippet is invalid, because `Example\MyNamespace\Foo::__set_state()` (which
does not exist) is called.

With this patch applied, the code looks like following (valid):

```php
<?php

namespace Example;

\MyNamespace\Foo::__set_state(array(
));
```

Ref: https://github.com/php/php-src/issues/8232
Ref: https://github.com/Ocramius/ProxyManager/issues/754
Ref: https://externals.io/message/117466
2022-04-23 11:06:21 +02:00
Nikita Popov
902d64390e Deprecate implicit dynamic properties
Writing to a proprety that hasn't been declared is deprecated,
unless the class uses the #[AllowDynamicProperties] attribute or
defines __get()/__set().

RFC: https://wiki.php.net/rfc/deprecate_dynamic_properties
2021-11-26 14:10:11 +01:00
Kamil Tekiela
c3dda473cc Fix 'can not' in test data and in code comments 2021-10-05 09:51:58 +01:00
Hao Sun
0dd187373a Merge branch 'PHP-8.1'
* PHP-8.1:
  ARM64: range.phpt failed under RELEASE mode

Change-Id: Ia7d0e1e6710aaebc5968bd67a0c3ad324c809dd8
2021-09-29 09:15:44 +00:00
Hao Sun
cfa88b7579 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  ARM64: range.phpt failed under RELEASE mode

Change-Id: I10bec6995ea362ca98f7e607db7026598455b643
2021-09-29 09:15:31 +00:00
Hao Sun
6f6fd27d2f ARM64: range.phpt failed under RELEASE mode
Test case "ext/standard/tests/array/range.phpt" failed on ARM64 machine
only under RELEASE mode.

How to reproduce it:
```
./buildconf -f; ./configure; make -j 128
make test TESTS="-d opcache.enable=1 -d opcache.enable_cli=1 ext/standard/tests/array/range.phpt"
```

Root cause:
I suspect the root cause is that on ARM64 machine, PHP RELEASE mode
produces different values for internal function range() compared to
DEBUG mode.

Take the downsized test case downsize-range.php [1] as an example. We
applied the check-element.diff patch to check the original values. Note
that we print out the floating point numbers with precision 16.

From the outputs in file output.md, we can see the 7-th and 9-th
elements are different between RELEASE and DEBUG.

To be honest, I didn't get where such difference comes from and probably
this is due to different compilation options used by RELEASED and DEBUG.

Fix:
After commit [2], serialize_precision is used for var_dump(). As a
result, the pre-set "precision=14" didn't work actually.

In this patch, we turn to set serialize_precision as 14 and therefore
the difference between RELEASE and DEBUG can be eliminated.

Note-1: this failue didn't occur on x86 machine.
Note-2: in my local test, this is the only test case which behaves
differently on ARM64 machine under RELEASE and DEBUG mode.

[1] https://gist.github.com/shqking/0d55abf8dbaafde4a00ea9304e71f06b
[2] https://github.com/php/php-src/commit/a939805

Change-Id: I9293e990925590f8d7cfb2462d8d760abf76069f
2021-09-29 09:07:17 +00:00