Commit Graph

1245 Commits

Author SHA1 Message Date
Jakub Zelenka
f288d9c4b0
Merge branch 'PHP-8.3' 2023-11-03 17:18:40 +00:00
Jakub Zelenka
52b13f6ddb
Merge branch 'PHP-8.2' into PHP-8.3 2023-11-03 17:17:52 +00: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
f39b0292bf
Merge branch 'PHP-8.3'
* PHP-8.3:
  Fix double-free of doc_comment when overriding static property via trait
2023-10-19 15:23:34 +02:00
Ilija Tovilo
8347740c8c
Merge branch 'PHP-8.2' into PHP-8.3
* PHP-8.2:
  Fix double-free of doc_comment when overriding static property via trait
2023-10-19 15:23:26 +02: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
Niels Dossche
cdfa016854
Avoid refcounted copy in _object_properties_init() for internal classes (#12474)
This currently uses ZVAL_COPY_OR_DUP, which copies the value and handles
refcounting. However, internal classes cannot have refcounted default
properties because of constraints imposed by
zend_declare_typed_property(). So copying the value is sufficient.

While this doesn't really improve the performance for our benchmarks, it
improves performance for cases where a lot of temporary internal objects
are instantiated. For example, when instantiating DOM classes: DOM
objects are transient, so lots of temporary objects are created.
2023-10-19 12:34:55 +02:00
George Peter Banyard
d86314939c Zend: Add ZPP F type check for callables that do not free trampolines
As refetching it with the new FCC API does get tedious
2023-10-10 13:44:21 +01:00
Niels Dossche
9b6afd88fb
Make sure core module has number 0 (#12272)
* Make sure core module has number 0

Some places, possibly also outside PHP, assume the core extension has
module number 0. After 8a812c3fda this wasn't the case anymore as
reported in [1]. Fix it by changing how the next module ID is computed.

[1] https://github.com/php/php-src/pull/12246#issuecomment-1731432377

* Add assertion

* Add test
2023-09-25 17:36:13 +02:00
Niels Dossche
8a812c3fda Fix GH-12215: Module entry being overwritten causes type errors in ext/dom (PHP 8.4)
When we try to load an extension multiple times, we still overwrite the
type, module number, and handle. If the module number is used to
indicate module boundaries (e.g. in reflection and in dom, see e.g.
dom_objects_set_class_ex), then all sorts of errors can happen.

In the case of ext/dom, OP's error happens because the following
happens:
- The property handler is set up incorrectly in
  dom_objects_set_class_ex() because the wrong module number is
  specified. The class highest in the hierarchy is DOMNode, so the
  property handler is incorrectly set to that of DOMNode instead of
  DOMDocument.
- The documentElement property doesn't exist on DOMNode, it only exists
  on DOMDocument, so it tries to read using zend_std_read_property().
  As there is no user property called documentElement, that read
  operation returns an undef value.
  However, the type is still checked, resulting in the strange exception.

Solve this by changing the API such that the data is only overwritten if
it's owned data.

Closes GH-12246.
2023-09-20 21:02:51 +02:00
Ilija Tovilo
f957335c66
Move static property check to assert (#12239)
Staticness incompatiblity must error before attempting to declare the property.
2023-09-19 10:35:25 +02:00
David Carlier
639bcb4078 Merge branch 'PHP-8.2' into PHP-8.3 2023-09-18 17:46:28 +01: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
Jakub Zelenka
53aa53f42f
Introduce Zend guard recursion protection
This PR introduces a new way of recursion protection in JSON, var_dump
and friends. It fixes issue in master for __debugInfo and also improves
perf for jsonSerializable in some cases. More info can be found in
GH-10020.

Closes GH-11812
2023-08-24 13:03:14 +01:00
ju1ius
7f1c3bf09b
Adds support for DNF types in internal functions and properties (#11969)
Note that this does not add support for items generated by gen_stubs,
only for items registered dynamically via the Zend API.

Closes GH-10120
2023-08-19 00:11:06 +01:00
George Peter Banyard
80e90ad7ba
Add number or str ZPP macros 2023-06-18 13:09:03 +01:00
George Peter Banyard
d5ad75108e
More usage of known zend_str instead of C string (#11381) 2023-06-08 13:03:29 +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
9ce6980b4d
Use known zend_string pointer to check for equality instead of C strings (#11370)
* Compare __invoke magic method name with known zend_string pointer

* Compare __sleep/__wakeup magic method name with known zend_string pointer
2023-06-05 13:59:04 +01:00
Máté Kocsis
414f71a902
Typed class constants (#10444)
RFC: https://wiki.php.net/rfc/typed_class_constants

Co-Authored-By: Ben <7127204+moliata@users.noreply.github.com>
Co-Authored-By: Bob Weinand <3154871+bwoebi@users.noreply.github.com>
Co-Authored-By: Ilija Tovilo <ilija.tovilo@me.com>
2023-04-16 22:20:26 +02:00
Dmitry Stogov
c9d728cbd6 Revert "Zend/zend_types.h: move zend_rc_debug to zend_rc_debug.h"
This reverts commit d6e95041e2.
2023-04-04 22:48:26 +03:00
Máté Kocsis
574e531127
Micro optimization: readonly properties always have a type 2023-03-09 10:03:47 +01:00
Ilija Tovilo
6a7115359e
Fix gcc warnings in zend_API.c with --disable-debug (#10786)
-Warray-bounds complains about malloc(sizeof(zend_arg_info) * num_args) being
smaller than zend_function when dereferencing reg_function.
2023-03-05 21:38:05 +01:00
Máté Kocsis
3bcf2c3755
Allow readonly properties to be reinitialized once during cloning (#10389)
RFC: https://wiki.php.net/rfc/readonly_amendments
2023-02-28 22:54:38 +01:00
Max Kellermann
d6e95041e2 Zend/zend_types.h: move zend_rc_debug to zend_rc_debug.h
`zend_rc_debug` is not a type and does not really belong in
`zend_types.h`; this allows using `ZEND_RC_MOD_CHECK()` without
including the huge `zend_types.h` header and allows decoupling
circular header dependencies.
2023-02-26 14:16:53 +00:00
Niels Dossche
9108a32bfe
Minor cleanups in Zend execution APIs (#10699)
* Remove always-false check in zend_lookup_class_ex()

This check is always false because of the undefined behaviour rule that
says a NULL pointer must never be dereferenced: we already dereference name
when checking the cache slot, before the NULL check. So the NULL may be
optimised away by the compiler. It looks like the code isn't even
supposed to work with name being NULL, so just remove the check.

* Remove always-true check in zend_fetch_static_property_address_ex()

* Simplify always-true conditions
2023-02-26 14:15:04 +00:00
David Carlier
ad7d3c888d Merge branch 'PHP-8.2' 2023-02-24 17:03:50 +00: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
Max Kellermann
d5c649b36b
zend_compiler, ...: use uint8_t instead of zend_uchar (#10621)
`zend_uchar` suggests that the value is an ASCII character, but here,
it's about very small integers.  This is misleading, so let's use a
C99 integer instead.

On all architectures currently supported by PHP, `zend_uchar` and
`uint8_t` are identical.  This change is only about code readability.
2023-02-23 14:56:54 +00:00
Niels Dossche
821fc55a68
Implement GH-9826: Make class_alias() work with internal classes (#10483)
We can't increase the refcount of internal classes during request time.
To work around this problem we simply don't refcount aliases anymore and
add a check in the destruction to skip aliases entirely.
There were also some checks which checked for an alias implicitly by
comparing the refcount, these have been replaced by checking the type of
the zval instead.
2023-02-22 11:47:32 +01:00
Max Kellermann
413844d626
Zend/zend_types.h: deprecate zend_bool, zend_intptr_t, zend_uintptr_t (#10597)
These types are standard C99.

For compatibility with out-of-tree extensions, keep the typedefs
in main/php.h.
2023-02-18 19:31:28 +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 Dossche
8d21a6b2ab
Fix UNEXPECTED() paren mistakes.
This corrects the paren placement to the intended one.
As these functions use zend_result, the success value is zero. Therefore
this has no functional change. The only difference is that this now
hints the compiler optimizer correctly.

Closes GH-10364.
2023-01-18 15:14:44 +01:00
Bob Weinand
277dc35541 Merge branch 'PHP-8.2' 2023-01-16 17:39:34 +01: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
Christoph M. Becker
bf1cfc0753
Revert GH-10300
Cf. <https://github.com/php/php-src/pull/10220#issuecomment-1383739816>.

This reverts commit 68ada76f9a.
his reverts commit 45384c6e20.
This reverts commit ef7fbfd710.
This reverts commit 9b9ea0d7c6.
This reverts commit f15747c26b.
This reverts commit e883ba93c4.
This reverts commit 7e87551c37.
This reverts commit 921274d2b8.
This reverts commit fc1f528e5e.
This reverts commit 0961715cda.
This reverts commit a93f264526.
This reverts commit 72dd94e1c6.
This reverts commit 29b2dc8964.
This reverts commit 05c7653bba.
This reverts commit 5190e5c260.
This reverts commit 6b55bf228c.
This reverts commit 184b4a12d3.
This reverts commit 4c31b7888a.
This reverts commit d44e9680f0.
This reverts commit 4069a5c43f.
2023-01-16 12:22:54 +01:00
Max Kellermann
ef7fbfd710 Zend/zend_API: include cleanup 2023-01-15 15:07:58 +00:00
Max Kellermann
f5149535e8 Zend/zend_API: make several pointers const 2023-01-04 12:59:16 +00:00
George Peter Banyard
4cee2c0127
Use proper int|float union type instead of numeric (#10162) 2022-12-28 13:35:19 +00:00
Bob Weinand
2cab4874ad Merge branch 'PHP-8.2' 2022-11-09 16:36:50 +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
George Peter Banyard
de4cfff5f6 Add various APIs to handle FCC structures 2022-11-02 14:52:54 +00:00
George Peter Banyard
7c45b95894 Store a reference to closures in the FCC 2022-11-02 14:52:54 +00: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