Commit Graph

1208 Commits

Author SHA1 Message Date
Niels Dossche
2f605820a4 Workaround ZTS persistent resource crashes (PHP 8.3 and lower)
For master (8.4-dev) I merged GH-13381. But that PR changes public API
of TSRM, so cannot be used on lower branches.

This patch is a safe workaround for the issue, in combination with a
pre-existing fix using `ifdef ZTS + if (module_started)` inside pgsql
and odbc. The idea is to delay unloading modules until the persistent
resources are destroyed. This will keep the destructor code accessible
in memory.

This is not a proper fix on its own, because we still need the
workaround of not accessing globals after module destruction.
The proper fix is in master.

Closes GH-13388.
2024-02-20 21:24:43 +01:00
Jakub Zelenka
882cc4f804
Merge branch 'PHP-8.1' into PHP-8.2 2023-11-03 17:17:23 +00:00
Jakub Zelenka
a8c6c6165b
Fix GH-9921: Loading ext in FPM config does not register module handlers
Closes GH-12377
2023-11-03 16:53:09 +00:00
Ilija Tovilo
4f1f77c51b
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix double-free of doc_comment when overriding static property via trait
2023-10-19 15:23:00 +02:00
Ilija Tovilo
af3d2f7ec9
Fix double-free of doc_comment when overriding static property via trait
When redeclaring an overridden static property with a trait we're removing the
property from the class. However, because the property itself does not belong to
the class we must not free its associated data.

This issue is exposed by 9a250cc9d6 in PHP 8.3+ because duplicate static
properties in traits are no longer skipped, but redeclared.

Fixes GH-12468
2023-10-19 15:21:53 +02:00
David Carlier
c39d4481c5 Merge branch 'PHP-8.1' into PHP-8.2 2023-09-18 17:46:11 +01:00
Florian Sowade
910f579f14 Fix GH-12207 memory leak of doc blocks of static properties
When declaring the same static property with a doc block in a class and in a trait,
the doc block of the property in the class is leaked. While at it, possibly fix doc
 comment for internal classes.

Close GH-12238
2023-09-18 17:44:47 +01:00
David Carlier
9cac68d678 Merge branch 'PHP-8.1' into PHP-8.2 2023-02-24 17:03:00 +00:00
nielsdos
8959ff39d8 Fix incorrect type for return value of zend_update_static_property_ex()
zend_update_static_property_ex() returns a zend_result, but the return
value is stored here in a bool. A bool is unsigned on my system, so in
case zend_update_static_property_ex() returns FAILURE (== -1) this gets
converted to 1 instead. This is not a valid zend_result value. This
means that (transitive) callers could mistakingly think the function
succeeded while it did in fact not succeed. Fix it by changing the type
to zend_result.

Closes GH-10691.
2023-02-24 17:02:32 +00:00
Petar Obradović
e560592a61 Fix GH-9675: Re-adjust run_time_cache init for internal enum methods
Closes GH-10143.
2023-01-16 17:38:38 +01:00
Bob Weinand
182314c317 Do not report MINIT stage internal class aliases in extensions
Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-11-09 16:36:05 +01:00
Máté Kocsis
adb45a63c0
Fix GH-9186 @strict-properties can be bypassed using unserialization (#9354)
* Emit deprecation warnings when adding dynamic properties to classes during unserialization - this will become an Error in php 9.0.
  (Adding dynamic properties in other contexts was already a deprecation warning - the use case of unserialization was overlooked)
* Throw an error when attempting to add a dynamic property to a `readonly` class when unserializing
* Add new serialization methods `__serialize`/`__unserialize` for SplFixedArray to avoid creating deprecated dynamic
  properties that would then be added to the backing fixed-size array
* Don't add named dynamic/declared properties (e.g. $obj->foo) of SplFixedArray to the backing array when unserializing
* Update tests to declare properties or to expect the deprecation warning
* Add news entry

Co-authored-by: Tyson Andre <tysonandre775@hotmail.com>
2022-08-30 07:46:32 -04:00
Bob Weinand
bf427b732a Add an API to observe functions and classes being linked
To observe when the functions and classes start being officially available to the user

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-23 15:22:22 +02:00
Bob Weinand
dc5475c191 Save previous observer on the VM stack
This avoids a possible significant performance penalty, when some leaf function was observed, deep in the stack.
As a side effect, we are not iterating over prev_execute_data anymore and thus, non-observed fake frames, possibly on stack, cannot have any impact on the observer anymore (especially within zend_observer_fcall_end_all).

Saving the previous observer happens now directly on the VM stack. If there is any observer, function frames are allocated an extra zval (the last temporary), which will, on observed frames, contain the previous observed frame address.
2022-08-04 17:16:27 +02:00
George Peter Banyard
faa83f2f34
Convert some macros to zend_always_inline functions (#8288)
This doesn't have an effect really, but humans and IDEs can struggle to see through the macro soup when they first interact with PHP's source code.

Moreover, this reduces some of the macro expansion hell when they appear in compiler warnings.
2022-08-04 13:24:12 +01:00
Bob Weinand
625f164963 Include internal functions in the observer API
There are two main motivations to this:
a) The logic for handling internal and userland observation can be unified.
b) Unwinding of observed functions on a bailout does notably not include observers. Even if users of observers were to ensure such handling themselves, it would be impossible to retain the relative ordering - either the user has to unwind all internal observed frames before the automatic unwinding (zend_observer_fcall_end_all) or afterwards, but not properly interleaved.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-07-30 19:20:55 +02:00
Ilija Tovilo
7aadbcb8f4
GH-8344 Fetch properties of enums in const expressions 2022-07-18 23:52:28 +02: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
George Peter Banyard
f905590764
Add support for Disjoint Normal Form (DNF) types (#8725)
RFC: https://wiki.php.net/rfc/dnf_types

This allows to combine union and intersection types together in the following form (A&B)|(X&Y)|T but not of the form (X|A)&(Y|B) or (X|A)&(Y|B)|T.

* Improve union type parsing

Co-authored-by: Sara Golemon <pollita@php.net>
2022-07-08 11:30:23 +01:00
twosee
4a9c001140
Add clean_module_functions() (#8763)
Add clean_module_functions() to clean functions which are registered by zend_register_functions().
The general logic of clean_module_functions() is consistent with clean_module_classes().
2022-06-17 16:33:20 +02:00
Ilija Tovilo
ddc0b490f7
Allow arbitrary const expressions in backed enums
Closes GH-7821
Closes GH-8190
Closes GH-8418
2022-06-12 22:56:05 +02:00
Jakub Zelenka
a6387fa383
Merge branch 'PHP-8.1' 2022-06-09 19:57:08 +01:00
Jakub Zelenka
976cbba76e Merge branch 'PHP-8.0' into PHP-8.1 2022-06-09 19:55:46 +01:00
Jakub Zelenka
b765d4cd41 Fix bug #50293 and #81713: file path checking in OpenSSL functions
It introduces a single function to check file paths passed to OpenSSL
functions. It expands the path, check null bytes and finally does
an open basedir check.
2022-06-09 19:49:59 +01:00
George Peter Banyard
b40ae80804
Convert iterable into an internal alias for Traversable|array (#7309)
This does a compile time transformation of ``iterable`` into ``Traversable|array`` which simplifies some of the LSP variance handling.

The arginfo generation script from stubs is updated to produce a union type when it encounters the type ``iterable``
Extension functions which do not regenerate the arginfo, or write them manually are still supported by mimicking the compile time transformation while registering the function.

Type Reflection is preserved for single ``iterable`` (and ``?iterable``) to produce a ReflectionNamedType with name ``iterable``, however usage of ``iterable`` in union types will be converted to ``array|Traversable``
2022-06-07 13:35:34 +01:00
Arnaud Le Blanc
e883407083 Merge branch 'PHP-8.1'
* PHP-8.1:
  Disable zend_rc_debug during dtor of dl()'ed module (#8606)
2022-05-24 19:23:48 +02:00
Arnaud Le Blanc
6cda01a05c
Disable zend_rc_debug during dtor of dl()'ed module (#8606)
Newly added dl() tests trigger an assertion in ZEND_RC_DEBUG builds. This change
disables zend_rc_debug to allows these tests to pass until this issue is
resolved.
2022-05-24 19:22:55 +02:00
Levi Morrison
b63df3ce0e
Stop copying zend_module_entry (#8551)
I did some historical digging and could not figure out why a copy is
made. Additionally, the copy was not using the `.size` member, so it
was probably wrong, but it's been that way for quite some time.
2022-05-24 09:13:38 -06:00
Arnaud Le Blanc
0a5a761104 Merge branch 'PHP-8.1' 2022-05-06 15:29:21 +02:00
Arnaud Le Blanc
f07a08df5c
Fix unregistering ini entries of dynamically loaded extension (#8435)
Fixes GH-8185
2022-05-06 15:25:44 +02:00
Ilija Tovilo
733023b2e3
Improve error message class type
Refer to interfaces/enums instead of classes in more places.

Closes GH-7792
Closes GH-8187
2022-03-20 20:54:36 +01:00
Nikita Popov
24485aa343 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix inheritance of class constants if mutable data used
2021-11-17 12:24:25 +01:00
Nikita Popov
44e5d25300 Fix inheritance of class constants if mutable data used
Class constants from parents should always be directly reused,
rather than re-evaluated as a separate copy. Previously this used
to happen automatically, as we'd just inherit the class constant
entry from the parent class. With mutable data there may now be
a separate copy of the constant, so we need to use that copy
when updating constants. Otherwise we may evaluate the same
constant multiple times.

Closes GH-7658.
2021-11-17 12:23:47 +01:00
Anton Vasiliev
0993821c16 Remove unused check_flags argument from zend_is_callable_check_func() 2021-11-15 09:41:07 +01:00
Nikita Popov
86379b6710 Warn if return type on internal __toString() is missing 2021-11-09 10:24:41 +01:00
Nikita Popov
85acad5688 Merge branch 'PHP-8.1'
* PHP-8.1:
  Add string return type to __toString() of internal classes
2021-11-09 10:21:16 +01:00
Nikita Popov
277caa1db0 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Add string return type to __toString() of internal classes
2021-11-09 10:20:36 +01:00
Nikita Popov
a551b08307 Add string return type to __toString() of internal classes
Same as with userland classes, automatically add a string return
type to __toString() methods in internal classes, so the signature
is compatible with Stringable.
2021-11-09 10:17:26 +01:00
Nikita Popov
edc02d2d94 Merge branch 'PHP-8.1'
* PHP-8.1:
  Implement Stringable automatically for internal classes
2021-11-05 10:24:07 +01:00
Nikita Popov
b0ec6223e2 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Implement Stringable automatically for internal classes
2021-11-05 10:23:23 +01:00
Nikita Popov
b302bfabe7 Implement Stringable automatically for internal classes
Requiring all internal classes (including those from 3rd-party
extensions) to implement Stringable if they provide __toString()
is too error prone. Case in point, our _ZendTestClass test class
was not doing so, resulting in preloading test failures after
recent changes.

Instead we automatically implement Stringable, the same as we do
for userland classes. We still allow explicit implementations,
but ignore them (normally they would result in an error due to
duplicate interface implementation). Finally, we need to be
careful about not trying to implement Stringable on Stringable
itself.

In some cases this changes the interface order, in particular the
automatic Stringable implementation will now come first.
2021-11-05 10:22:04 +01:00
Nikita Popov
2d38f701e0 Merge branch 'PHP-8.1'
* PHP-8.1:
  Don't implement Stringable on traits
2021-11-05 09:48:33 +01:00
Nikita Popov
4bdb271894 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Don't implement Stringable on traits
2021-11-05 09:48:28 +01:00
Nikita Popov
d478ae73b1 Don't implement Stringable on traits
Traits do not support interfaces, so we should not implement
Stringable on them.

Also check the __toString() return type in the same way other
magic methods do, otherwise we would now miss the check in the
trait case.
2021-11-05 09:42:58 +01:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
Nikita Popov
ee510eed68 Deprecate partially supported callables
This deprecates all callables that are accepted by
call_user_func($callable) but not by $callable(). In particular:

    "self::method"
    "parent::method"
    "static::method"
    ["self", "method"]
    ["parent", "method"]
    ["static", "method"]
    ["Foo", "Bar::method"]
    [new Foo, "Bar::method"]

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

Closes GH-7446.
2021-10-22 10:15:24 +02:00
Dmitry Stogov
ddaf64b56c Avoid non-immutable map_ptr indirection 2021-10-14 12:16:18 +03:00
Nikita Popov
2ffa70b97c Slightly clean up is_callable implementation
And adjust an error message to line up with the error message
used for $callable() in zend_execute.c.
2021-09-02 10:37:13 +02:00
Nikita Popov
449bb0577c Drop IS_CALLABLE_CHECK_SILENT flag
This flag was suppressing *some* but not all errors in
zend_is_callable(), and is no longer used. You can avoid errors
by omitting the error argument.
2021-09-01 16:13:39 +02:00
Nikita Popov
5b2ddf5a17 Export zend_use_resource_as_offset()
Use a common implementation to generate this error message, as
we do so in quite a few places dealing with array keys.
2021-08-31 10:58:01 +02:00