283 Commits
Author SHA1 Message Date
Gina Peter Banyard 8639e7522a ext/standard/basic_functions.c: return bool instead of int for connection_aborted() 2026-10-18 17:39:04 +01:00
Gina Peter Banyard fc5cafdec1 ext/standard/basic_functions.c: return bool instead of int for ignore_user_abort()
The INI setting is stored and displayed as a bool already.
2026-10-18 17:39:04 +01:00
Nicolas GrekasandArnaud Le Blanc 5b765f4b68 ext/standard: Return the input of htmlspecialchars() when nothing needs encoding (#23957)
htmlspecialchars() allocated a buffer of twice the input and decoded it
character by character, even when the result was the input itself.

The input is now scanned first for the characters that need encoding and
for invalid multi-byte sequences, with SSE2 on 16-byte blocks. When there
is none, the input string is returned, as html_entity_decode() and
htmlspecialchars_decode() already do since 68dc754998. Otherwise, encoding
starts after the part that was scanned.

The @refcount 1 annotations of htmlspecialchars() and htmlentities() are
removed since they can now return their argument.

Co-authored-by: Arnaud Le Blanc <365207+arnaud-lb@users.noreply.github.com>
2026-10-14 19:22:20 +02:00
Alexander Danilov 4561d52aaf Mark several functions with @compile-time-eval attribute. (#24212) 2026-10-09 23:32:28 +02:00
Weilin Du d650f5a68b ext/standard: Allow compile-time evaluation of more standard string functions (#23913)
Add it for str_increment() and str_decrement()
as they perform deterministic ASCII string operations
2026-09-28 00:20:56 +08:00
Weilin DuandNora Dossche 93fd714daa ext/standard: Optimize str_repeat() when the multiplier is one (#23681)
Just reuse the input string when the multiplier is one :)

Co-authored-by: Nora Dossche <7771979+ndossche@users.noreply.github.com>
2026-09-15 00:03:28 +08:00
Weilin Du 66c98704e2 ext/standard: Make ltrim() and rtrim() frameless 2026-09-05 18:13:39 +08:00
Weilin Du 027a5f8536 ext/standard: Make str_ends_with frameless (#23510)
Since str_starts_with is frameless, str_ends_with also
should be frameless.
2026-08-31 00:19:57 +08:00
Louis-Arnaud 1f2bcb8755 ext/standard: declare true as the return type of register_tick_function() (#23432)
The function either throws on an invalid callback or appends the entry
to the tick list and returns true; php_add_tick_function() returns void,
so there is nothing that could report a failure.
2026-08-25 16:54:42 +02:00
Louis-Arnaud f89291a94f ext/standard: declare true as the return type of header_register_callback() (#23402)
The function has a single non-throwing exit, RETURN_TRUE (main/SAPI.c).
The false return disappeared in PHP 8.0.0: until then an invalid callback
was rejected with RETURN_FALSE, whereas the zend_parse_parameters() 'f'
specifier introduced there throws a TypeError. Registering a callback
after the headers have been sent, the one case where the callback is
knowingly discarded, also returns true.

ksort(), asort() and natsort() already declare true in the same stub.
2026-08-22 03:58:21 +08:00
Ondrej Mirtes 89a17252a4 Make strtolower()/strtoupper() frameless
Both are single-argument wrappers around zend_string_tolower/upper;
static analyzers and general string handling call them at very high
frequency. The frameless call convention removes the call frame setup
and argument copying.

Co-authored-by: Markus Staab <maggus.staab@googlemail.com>
Closes GH-23084
2026-08-12 15:56:24 +02:00
Weilin Du 4b26ff1698 RFC: Deprecate metaphone() (#21889)
This implement RFC:
https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_metaphone_function
which deprecate the metaphone function.
2026-08-11 03:02:18 +08:00
Gina Peter Banyard 22217b3bbb standard: deprecate strcoll and SORT_LOCALE_STRING
RFCs:
- https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_strcoll
- https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_sort_locale_string_flag_for_sort_functions
2026-08-10 18:21:19 +01:00
Gina Peter Banyard 0b14af3b98 standard: deprecate aliases with non canonical type name
Fix tests using non canonical versions and improve existing tests.

RFC:
- https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_is_double
- https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_is_integer
- https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_is_long
- https://wiki.php.net/rfc/deprecations_php_8_6#deprecate_doubleval
2026-08-10 18:21:19 +01:00
Gina Peter Banyard 5795e330a6 sapi: convert current_user field to zend_string* (#22902)
Prevents some reallocations and strlen() recomputations
2026-07-30 13:30:10 +01:00
Jakub Zelenka 8816199556 Add stream crypto status for exposing OSSL WANT_READ / WANT_WRITE (#22193)
On a non-blocking stream, stream_socket_enable_crypto() returns 0 and
fread()/fwrite() return an empty result when the TLS engine needs more
I/O, but there was no way to tell whether OpenSSL was waiting to read or
to write. Callers therefore could not reliably decide which direction to
poll for with stream_select(), which is required to drive a non-blocking
handshake or renegotiation correctly (e.g. SSL_read() wanting a write).

This tracks the last SSL_ERROR_WANT_READ/WANT_WRITE on the stream and
exposes it via a new stream_socket_get_crypto_status() function and three
constants:

  STREAM_CRYPTO_STATUS_NONE
  STREAM_CRYPTO_STATUS_WANT_READ
  STREAM_CRYPTO_STATUS_WANT_WRITE

The status is updated during the handshake (php_openssl_enable_crypto())
and during reads/writes (php_openssl_sockop_io()), reset to NONE before
each operation, and retrieved through a new STREAM_XPORT_CRYPTO_OP_GET_STATUS
transport op. It is meaningful immediately after an operation that
returned 0/false on a non-blocking stream; a completed operation reports
NONE.

Tests cover the status during a non-blocking handshake, a non-blocking
read with no application data pending, and the constant values.
2026-06-04 19:02:11 +02:00
Ilija Tovilo 857593148d Fix stream_last_errors() rcn hint (GH-22194)
This function returns the static empty array, which has rc2 to avoid direct
mutation.
2026-05-31 12:23:51 +02:00
Jakub Zelenka f2b371e747 Add new stream erros API
This introduces new stream error handling that allows configurable
handling of stream errors. This can be configured in stream contex.

All streams, ext/standard and ext/phar stream errors are converted to
use the new API.

RFC: https://wiki.php.net/rfc/stream_errors

Closes GH-20524
2026-05-29 23:30:40 +02:00
Arnaud Le Blanc 2c5dc5d8b1 Add ZEND_ACC2_FORBID_DYN_CALLS
Functions that use zend_forbid_dynamic_call() must be flagged with
ZEND_ACC2_FORBID_DYN_CALLS. In stubs, this is done by using
@forbid-dynamic-calls.

To ensure consistency, we assert that the flag exists in
zend_forbid_dynamic_call(), and we assert that flagged functions thrown after a
dynamic call.

Closes GH-21818
2026-04-22 10:15:59 +02:00
Arnaud Le Blanc da58c65519 gen_stub: Support fn_flags2 flags
Change zend_function_entry.flags to a uint64_t to that both ZEND_ACC_ and
ZEND_ACC2_ flags can be represented.

Introduce ZEND_FENTRY_FLAGS(flags, flags2) to pass ZEND_ACC2_ flags to
ZEND_RAW_FENTRY(), ZEND_FENTRY().

Source-level backwards compatibility is maintained, as passing raw ZEND_ACC_
flags to ZEND_RAW_FENTRY(), ZEND_FENTRY() still works.
2026-04-22 10:15:59 +02:00
Ayesh Karunaratne 9e8dbc1d1c ext/standard: fix wrong array_filter() default value
Follow-up to GH-21100, that mistakenly set the default value of
the `array_filter()` as `ARRAY_FILTER_USE_KEY`, when it should
be `ARRAY_FILTER_USE_VALUE`, which is the newly defined constant.
2026-04-11 00:26:44 +05:30
Tim Düsterhus 32c1931f18 standard: Add enum SortDirection (#21501)
RFC: https://wiki.php.net/rfc/sort_direction_enum
2026-04-02 21:19:27 +02:00
Weilin Du da1e89fd3d RFC: Add Form Feed in Trim Functions (#20788)
RFC: https://wiki.php.net/rfc/trim_form_feed

Resolves GH-20783.
2026-03-09 22:28:50 +01:00
Arnaud Le Blanc d16e6f52a4 Generate C enums from internal enums, introduce Z_PARAM_ENUM() (#20917)
Update gen_stubs.php to generate C enums from internal enums, when the stub is annotated with @generate-c-enums. Enum values can be compared to the result of zend_enum_fetch_case_id(zend_object*).

The generated enums are added to separate files named {$extensionName}_decl.h, so that it's possible to include these from anywhere. _arginfo.h files would generate warnings if we tried to include them in a compilation unit that doesn't call the register_{$class} functions, for instance.

Introduce Z_PARAM_ENUM().

* Make ZEND_AST_CONST_ENUM_INIT a 4-children node

* Store enum case id in ZEND_AST_CONST_ENUM_INIT

* Store enum case id in instance

* Expose enum case_id internally

* Generate C enum for internal enums

* Introduce Z_PARAM_ENUM()

* Port extensions
2026-02-03 12:38:04 +01:00
Ayesh Karunaratne 6419618f54 ext/standard: update array_filter $mode param default value to ARRAY_FILTER_USE_VALUE
In GH-15647, the `array_filter` function was changed to throw a
`ValueError` exception when the `$mode` parameter receives an
invalid.

Additionally, it declares a new `ARRAY_FILTER_USE_VALUE`, assigned
(`int 1`) to it.

This changes the default value of the `array_filter` function's
`$mode` parameter to use the new constant, changing it from
`int $mode = 0` to `int $mode = ARRAY_FILTER_USE_KEY)`.

Closes GH-21100.
2026-02-01 10:35:32 +07:00
Jorg Adam Sowa 6d95a2238d ext/standard: validate mode in array_filter() (#15647)
And add the missing ARRAY_FILTER_USE_VALUE for the default case.
2026-01-26 16:02:15 +00:00
Kyleandthinkverse 06ea0e5df1 [RFC] Add clamp function (#19434)
* Implement clamp function

Co-authored-by: thinkverse <hallberg.kim@gmail.com>

* - Use a common function for normal and frameless implementations
- Add tests for null and not-comparable cases
- Fix object support for frameless clamp function
- Improve NAN handling

* Create tests triggering both frameless and dynamic variants

* Add changelog

* [Review] rephrase error messages to use "must not"

* Enable assert()

---------

Co-authored-by: thinkverse <hallberg.kim@gmail.com>
2025-12-18 20:27:30 +01:00
Daniel Scherzer 3f3a266a2b gen_stub: Infer constants' types from values (#19568)
Don't require `@var` with a type when the type can be inferred from a literal
value in the stub file.
2025-09-03 18:26:43 -07:00
Ilija Tovilo a544fe107e Fix glob() RC info
glob() can return the immutable, empty, RCn array since GH-19642.

Closes GH-19652
2025-08-31 14:18:46 +02:00
Tim Düsterhus 21625006e5 standard: Deprecate socket_set_timeout() (#19285)
RFC: https://wiki.php.net/rfc/deprecations_php_8_5#formally_deprecate_socket_set_timeout
2025-08-08 21:23:48 +01:00
Niels Dossche 8db883c540 Add API to register custom image handlers
This is modelled similarly to the password registry API.
We have an array to which new handlers can be added, and when a built-in
handler cannot handle the image, we try the handlers in the array.
The standard module is in control of registering a new constant for the
image file type so that no clashes can occur. It also updates the image
file type count constant. As such, the registration may only happen
during module startup.
2025-07-20 12:53:57 +02:00
Benstone Zhang dfac2da7fb Add support for HEIF/HEIC to getimagesize
Signed-off-by: Benstone Zhang <benstonezhang@gmail.com>
2025-07-19 19:24:45 +02:00
Niels Dossche c4183fba00 Fix GH-19070: setlocale($type, NULL) should not be deprecated
This restores the old behaviour.

Closes GH-19071.
2025-07-10 22:01:16 +02:00
DanielEScherzer 171501b93f Replace @deprecated with #[\Deprecated] for internal constants (#18780)
Only covers constants declared via stub files, others will be handled
separately in a later commit.

Does not include the intl extension, since that had some errors relating to the
cpp code; that extension will be updated separately.
2025-06-26 11:27:15 -07:00
Niels Dossche be23be08dc Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix RCN violations in array functions
2025-06-24 23:30:08 +02:00
Niels Dossche f77c04d007 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix RCN violations in array functions
2025-06-24 23:29:50 +02:00
Niels Dossche 359a21f102 Fix RCN violations in array functions
When the array functions perform their operation in-place, the
`@refcount 1` annotation is wrong and causes a failure under
`ZEND_VERIFY_FUNC_INFO`.
The test file tests all functions that have the in-place optimization,
even those that didn't have the refcount annotation, just to prevent
future regressions.

Closes GH-18929.
2025-06-24 23:29:00 +02:00
Calvin Buckley 76791e90b9 Use win32 glob implementation on all platforms (#18164)
* Move glob to main/ from win32/

In preparation to make the Win32 reimplementation the standard
cross-platform one. Currently, it doesn't do that and just passes
through the original glob implementation. We could consider also having
an option to use the standard glob for systems that have a sufficient
one.

* Enable building with win32 glob on non-windows

Kind of broken. We're namespacing the function and struct, but not yet
the GLOB_* defines. There are a lot of places callers check if i.e.
NOMATCH is defined that would likely become redundant.

Currently it also has php_glob and #defines glob php_glob (etc.) - I
suspect doing the opposite and changing the callers would make more
sense, just doing MVP to geet it to build (even if it fails tests).

* Massive first pass at conversion to internal glob

Have not tested yet. the big things are:

- Should be invisible to userland PHP code.
- A lot of :%s/GLOB_/PHP_GLOB_/g; the diff can be noisy as a result,
  especially in comments.
- Prefixes everything with PHP_ to avoid conflicts with system glob in
  case it gets included transitively.
- A lot of weird shared definitions that were sprawled out to other
  headers are now included in php_glob.h.
- A lot of (but not yet all cases) of HAVE_GLOB are removed, since we
  can always fall back to php_glob.
- Using the system glob is not wired up yet; it'll need more shim
  ifdefs for each flag type than just glob_t/glob/globfree defs.

* Fix inclusion of GLOB_ONLYDIR

This is a GNU extension, but we don't need to implement it, as the GNU
implementation is flawed enough that callers have to manually filter it
anyways; just provide a stub definition for the constant.

We could consideer implementing this properly later. For now, fixes the
basic glob constant tests.

* Remove HAVE_GLOBs

We now always have a glob implementation that works. HAVE_GLOB should
only be used to check if we have a system implementation, for if we
decide to wrap the system implementation instead.

* We don't need to care about being POSIXly correct for internal glob

* Check for reallocarray

Ideally temporary until GH-17433.

* Forgot to move this file from win32/ to main/

* Check for issetugid (BSD function)

* Allow using the system glob with --enable-system-glob

* Style fix after removing ifdef

* Remove empty case for system glob
2025-05-20 16:20:59 -03:00
Niels Dossche 168343d2e8 [RFC] Implement array_first() and array_last() (#18210) 2025-05-07 08:15:50 +02:00
haszi 701f3a1af6 Mark ob_start callback parameter nullable 2025-04-14 22:35:06 +02:00
Tim DüsterhusandVolker Dusch f14697416e ext/standard: Remove #[\NoDiscard] from flock() (#18255)
Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-04-08 14:23:03 +02:00
Tim DüsterhusandVolker Dusch 5544be7018 RFC: Marking return values as important (#[\NoDiscard]) (#17599)
RFC: https://wiki.php.net/rfc/marking_return_value_as_important

Co-authored-by: Volker Dusch <volker@tideways-gmbh.com>
2025-04-02 09:35:29 +02:00
Ilija Tovilo 47b7779329 Fix return type of error_get_last()
Since GH-17056, the result may return the backtrace array.

Closes GH-17641
2025-01-31 12:11:54 +01:00
Niels Dossche ecb90c1db7 Remove incorrect RC1 annotation for get_include_path() (#17301)
This annotation is wrong since GH-17294.
2024-12-30 14:38:30 +01:00
Gina Peter Banyard 573ad05a8d Merge branch 'PHP-8.4'
* PHP-8.4:
  ext/standard: Sync parameter names for fpow() to be identical to pow()
2024-11-11 13:07:02 +00:00
Gina Peter Banyard e7891838a1 ext/standard: Sync parameter names for fpow() to be identical to pow()
Closes GH-16751
2024-11-11 13:04:46 +00:00
Gina Peter Banyard 8143eca499 ext/standard: Change return value of array_multisort() to true (#16520)
It stopped being able to return false since PHP 8.0 when all warnings and false returns were converted to ValueErrors and TypeErrors
2024-10-22 11:07:42 +01:00
5905857fd2 RFC: Add the RoundingMode enum (#14833)
see https://wiki.php.net/rfc/correctly_name_the_rounding_mode_and_make_it_an_enum

Co-authored-by: Saki Takamachi <saki@php.net>
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2024-07-18 20:44:30 +02:00
Ayesh Karunaratne 673b4e890c ext/standard: change highlight_string()/print_r stub return type from string|bool to string|true (#14959)
* ext/standard: change `highlight_string()` return type from `string|bool` to `string|true`

* ext/standard: change `print_r` return type from `string|bool` to `string|true`
2024-07-15 23:20:32 +02:00
29f98e7485 Replace @deprecated by #[\Deprecated] for internal functions / class constants (#14750)
Co-authored-by: Gina Peter Banyard <girgias@php.net>
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2024-07-10 16:47:31 +02:00