1
0
mirror of https://github.com/php/php-src.git synced 2026-04-21 15:08:16 +02:00
Commit Graph

2699 Commits

Author SHA1 Message Date
Máté Kocsis b73f139c70 Declare ext/spl constants in stubs (#9226) 2022-08-02 16:37:12 +02:00
George Peter Banyard 1478278f1d SPL: Use new improved is_line_empty() function instead of the old one (#9217) 2022-08-01 17:55:30 +01:00
George Peter Banyard 7ab22aad9e Refactor code handling file.current_zval (#8934)
The Zval is always an array
2022-07-28 19:36:30 +01:00
Jakub Zelenka 1a9e6895f1 Fix #65069: GlobIterator incorrect handling of open_basedir check
This PR changes the glob stream wrapper so it impacts "glob://"
streamsas well. The idea is to do a check for each found path instead
of the pattern which was not working correctly.
2022-07-28 11:42:42 +01:00
Christoph M. Becker 5d52d472ef Fix #69181: READ_CSV|DROP_NEW_LINE drops newlines within fields
One may argue that `DROP_NEW_LINE` does not make sense in combination
with `READ_CSV`, but without `DROP_NEW_LINE`, `SKIP_EMPTY` does not
skip empty lines at all.  We could fix that, but do not for BC reasons.
Instead we no longer drop newlines in `spl_filesystem_file_read_ex()`
when reading CSV, but handle that in `spl_filesystem_file_read_csv()`
by treating lines with only (CR)LF as being empty as well.

Closes GH-7618.
2022-07-26 18:33:57 +02:00
Ilija Tovilo b5ab0e06b8 Assert all test files are cleaned up in CI (#8977)
Closes GH-8427
2022-07-21 16:06:14 +01:00
George Peter Banyard 11c424c9fb Remove unnecessary include in SPL 2022-07-21 14:46:39 +01:00
Ilija Tovilo d4a9cc8856 Fix rc info of iterator_to_array (#9080)
This function can now return a copy of the provided array, resulting in
a value of RC != 1.
2022-07-21 15:05:34 +02:00
Tim Düsterhus 7ae7df5b46 RFC: Make the iterator_*() family accept all iterables (#8819)
https://wiki.php.net/rfc/iterator_xyz_accept_array
2022-07-19 16:46:32 +02:00
Go Kudo 4d8dd8d258 Implement Random Extension
https://wiki.php.net/rfc/rng_extension
https://wiki.php.net/rfc/random_extension_improvement
2022-07-19 10:27:38 +01:00
Rowan Tommins af15923bc3 Extend deprecation notices to is_callable($foo) and callable $foo
Implements https://wiki.php.net/rfc/partially-supported-callables-expand-deprecation-notices
so that uses of "self" and "parent" in is_callable() and callable
type constraints now raise a deprecation notice, independent of the
one raised when and if the callable is actually invoked.

A new flag is added to the existing check_flags parameter of
zend_is_callable / zend_is_callable_ex, for use in internal calls
that would otherwise repeat the notice multiple times. In particular,
arguments to internal function calls are checked first based on
arginfo, and then again during ZPP, so the former suppresses the
deprecation notice.

Some existing tests which raised this deprecation have been updated
to avoid the syntax, but the existing version retained for maximum
regression coverage until it is made an error.

With thanks to Juliette Reinders Folmer for the RFC and initial
investigation.

Closes GH-8823.
2022-07-14 17:07:42 +02:00
Arnaud Le Blanc 4df3dd7679 Reduce memory allocated by var_export, json_encode, serialize, and other (#8902)
smart_str uses an over-allocated string to optimize for append operations. Functions that use smart_str tend to return the over-allocated string directly. This results in unnecessary memory usage, especially for small strings.

The overhead can be up to 231 bytes for strings smaller than that, and 4095 for other strings. This can be avoided for strings smaller than `4096 - zend_string header size - 1` by reallocating the string.

This change introduces `smart_str_trim_to_size()`, and calls it in `smart_str_extract()`. Functions that use `smart_str` are updated to use `smart_str_extract()`.

Fixes GH-8896
2022-07-08 14:47:46 +02:00
George Peter Banyard 4ccf0b0181 Make php_fgetcsv() return a HashTale instead of in-out zval param (#8936)
Also refactor what happens on an empty line to return NULL instead of setting the array to [NULL] which makes no design sense at all.
However, as this is the current behaviour create a BC Shim inline function to recreate this weird HashTable in the functions which currently use this API
2022-07-08 12:11:05 +01:00
George Peter Banyard 247de8a4de Use true/false and comment when arg correspond to silent arg 2022-07-08 11:36:59 +01:00
George Peter Banyard bb3d0933af Remove silent argument to spl_filesystem_file_read_line_ex()
true was always passed to it
2022-07-08 11:36:59 +01:00
George Peter Banyard a055c54801 Remove silent argument to spl_filesystem_file_read_line()
true was always passed to it
2022-07-08 11:36:59 +01:00
George Peter Banyard 6f26102bbf Merge branch 'PHP-8.1'
* PHP-8.1:
  Revert "Fix GH-8563  Different results for seek() on SplFileObject and SplTempFileObject"
  Revert "Update FreeBSD CI image."
2022-07-05 21:45:13 +01:00
George Peter Banyard e67336f46a Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Revert "Fix GH-8563  Different results for seek() on SplFileObject and SplTempFileObject"
2022-07-05 21:33:47 +01:00
George Peter Banyard 79a283240e Revert "Fix GH-8563 Different results for seek() on SplFileObject and SplTempFileObject"
Although the fix is partially correct it also breaks long standing behaviour which has been produced since PHP 5.3.

This reverts commit 6f87a5c633.
2022-07-05 21:28:59 +01:00
David Carlier dfbb425295 Use safe_*erealloc* flavor in few places to mitigate possible overflows. 2022-07-04 14:41:04 +01:00
George Peter Banyard 9bae9ab3a4 Fix GH-8861: correctly handle string lengths in SplFileinfo methods (#8869)
* Fix GH-8861: correctly handle string lengths in \SplFileinfo::getBasename

Co-authored-by: M. Vondano <m-vo@users.noreply.github.com>
2022-06-28 15:42:59 +01:00
Ilija Tovilo 3b92a96610 Convert return type of various object handlers from int to zend_result (#8755) 2022-06-26 01:00:19 +02:00
George Peter Banyard 20638dba3f Use the passed 'this' pointer instead of ZEND_THIS (#8854)
Removes the horrible hack usage of defining execute_data to be able to use ZEND_THING
2022-06-24 03:38:29 +01:00
George Peter Banyard 7cd8879d77 Refactor spl_filesystem_object_get_path() to return zend_string* 2022-06-23 14:41:24 +01:00
George Peter Banyard 623fbfe748 Remove Z_SPLFILESYSTEM_P macro
Remove one level of macro expansion hell
2022-06-23 14:41:24 +01:00
George Peter Banyard 4d43241e96 Move some private SPL Directory elements out of the header 2022-06-23 14:41:24 +01:00
George Peter Banyard d5d0b07b4e Early return in spl_filesystem_file_rewind() 2022-06-20 17:27:35 +01:00
George Peter Banyard a493c94471 Use bool for silent parameter in SPL directory.c 2022-06-20 17:27:25 +01:00
cmp 6bd0175173 Prevent fclose on underlying SplFileObject file stream. (#7920) 2022-06-20 13:37:59 +01:00
George Peter Banyard 8c50b8d797 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8563  Different results for seek() on SplFileObject and SplTempFileObject
2022-06-20 12:53:26 +01:00
George Peter Banyard 080fde2605 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8563  Different results for seek() on SplFileObject and SplTempFileObject
2022-06-20 12:53:01 +01:00
George Peter Banyard 6f87a5c633 Fix GH-8563 Different results for seek() on SplFileObject and SplTempFileObject
With memory streams if we get a NULL buffer we must not instantiate an empty line
2022-06-20 12:47:37 +01:00
Pierrick Charron 1bcd8d394a Update gen_stub to support #if around classes 2022-06-13 16:34:12 -04:00
George Peter Banyard dbf1cafd77 Remove internal usage of SplFileInfo::_bad_state_ex() method (#8318)
* Use standard VM handling instead
 * Deprecate the method as it is now useless
2022-06-09 13:24:58 +01:00
George Peter Banyard f800c60f13 Merge branch 'PHP-8.0' into PHP-8.1 2022-06-08 11:43:22 +01:00
George Peter Banyard 52eb52d652 Backport fcba0a49fc
Forgot this file exists in lower branches
2022-06-08 11:43:12 +01:00
George Peter Banyard fcba0a49fc Fix test file name to not include a whitespace
This breaks the preload file flag in the test runner
2022-05-31 11:28:01 +01:00
George Peter Banyard fc799ecdbe Move SplFileObject tests into subfolder 2022-05-27 18:33:48 +01:00
Christoph M. Becker e5d9859b50 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8235: iterator_count() may run indefinitely
2022-05-03 12:59:59 +02:00
Christoph M. Becker e004e1a93b Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8235: iterator_count() may run indefinitely
2022-05-03 12:59:39 +02:00
Christoph M. Becker ad7b9f4e50 Fix GH-8235: iterator_count() may run indefinitely
We need to prevent integer overflow to eventually stop the iteration.

A test case doesn't appear sensible for this, because even on 32bit
architectures a respective test easily runs for a few minutes.

Closes GH-8447.
2022-05-03 12:57:58 +02:00
George Peter Banyard cf51d8ffe7 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8273: SplFileObject: key() returns wrong value
2022-04-23 14:02:01 +01:00
George Peter Banyard 660ef91fbc Fix GH-8273: SplFileObject: key() returns wrong value 2022-04-23 14:00:11 +01:00
George Peter Banyard 6186ecd436 Fix GH-8273: SplFileObject: key() returns wrong value 2022-04-23 13:56:38 +01: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
Christoph M. Becker 3de0ccfe09 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix GH-8366: ArrayIterator may leak when calling __construct()
2022-04-15 19:10:29 +02:00
Christoph M. Becker 549cf3a24d Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix GH-8366: ArrayIterator may leak when calling __construct()
2022-04-15 19:08:28 +02:00
Christoph M. Becker 1762a87932 Fix GH-8366: ArrayIterator may leak when calling __construct()
When we detach an iterator, we also have to delete it.

Closes GH-8374.
2022-04-15 19:05:18 +02:00
George Peter Banyard cfc38a6014 SPL: minor refactoring (#8341)
Use more appropriate types and return macros
2022-04-13 20:34:23 +01:00
George Peter Banyard 7710f9946b Fix generation of arginfo if type is just null 2022-04-11 16:58:13 +01:00