1
0
mirror of https://github.com/php/php-src.git synced 2026-03-24 00:02:20 +01:00

527 Commits

Author SHA1 Message Date
Gina Peter Banyard
f40b356ad9 Use smart_str_append() if we have a zend_string* (#21414) 2026-03-21 17:06:14 +00:00
Gina Peter Banyard
f93b17076a Zend: inherit interfaces early (#18622)
The primary motivation for this is that this is required for my abstract generic types proof of concept, as the resolving of bound types needs to happen early to properly track the types.

However, there doesn't seem to be a good reason for delaying the inheritance of interfaces.
This approach might even allow us to drop the `iface` parameter of the `interface_gets_implemented()` handler as the interface name is always known.
2026-03-09 21:57:50 +00:00
Gina Peter Banyard
1096ea149a Zend: mark variable as const 2026-03-09 21:41:06 +00:00
Gina Peter Banyard
032e5f6774 Zend: mark arg_info parameters of zend_do_perform_arg_type_hint_check() const 2026-03-09 21:41:06 +00:00
Gina Peter Banyard
2b20627cbc Zend: mark zend_perform_covariant_type_check() as static
This function is not defined in any headers
2026-03-09 21:41:06 +00:00
Gina Peter Banyard
6880a6c49d Zend: mark scope parameter of zend_type_to_string_resolved() const
And propagate const qualifier to use sites of this function.
2026-03-09 21:41:06 +00:00
Ilija Tovilo
cccc54872a Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix incorrect property_info sizing for locally shadowed trait properties
2026-03-09 13:50:59 +01:00
Ilija Tovilo
ff3f59b5a7 Fix incorrect property_info sizing for locally shadowed trait properties
Previously, static trait properties would always redeclare locally declared
static properties to make sure any inherited property would stop sharing a
common slot with the parent. This would leave holes in property_info, creating
issues for this code:

    zend_hash_extend(&ce->properties_info,
        zend_hash_num_elements(&ce->properties_info) +
        zend_hash_num_elements(&parent_ce->properties_info), 0);

where zend_hash_num_elements(&ce->properties_info) +
zend_hash_num_elements(&parent_ce->properties_info) is supposed to extend the
hash table enough to hold all additional properties coming from parent. However,
if ce->properties_info contains holes this might not be enough, given all parent
properties are appended at nNumUsed.

This could be fixed by further extending the hash table, but we can also avoid
the holes in properties_info completely by not redeclaring trait properties that
are already declared in the target class. This is now possible because traits
are bound before performing parent class inheritance, so if the property is
already present we know it will separate the property slot.

Fixes GH-20672
Closes GH-21358
2026-03-09 13:50:27 +01:00
Tim Düsterhus
303104e2bf zend: Define C23 enum zend_class_type (#21241)
Checked for “binary and” comparisons using Coccinelle:

    @@
    struct _zend_class_entry *e;
    expression x;
    @@

    * (e->type & x)

    @@
    zend_class_entry *e;
    expression x;
    @@

    * (e->type & x)
2026-02-17 16:49:45 +01:00
Arshid
b5abd77bdf [skip ci] Remove unreachable code after zend_error_noreturn calls (GH-21122) 2026-02-03 22:02:43 +01:00
Khaled Alam
32bd33983d Remove unreachable code after zend_error_noreturn calls (GH-20983) 2026-02-02 14:14:15 +01:00
Ilija Tovilo
dc03108459 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix leaked parent property default value
2026-01-13 13:09:29 +01:00
Ilija Tovilo
c35e391b2d Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix leaked parent property default value
2026-01-13 13:09:23 +01:00
Ilija Tovilo
4bfaf549f6 Fix leaked parent property default value
Fixes OSS-Fuzz #474613951
Closes GH-20911
2026-01-13 13:08:39 +01:00
Arnaud Le Blanc
626f3c3c7c Unify arg info representation for internal and user functions
The arg_info member of zend_function is now always a zend_arg_info*. Before,
it was a zend_internal_arg_info* on internal functions, unless the
ZEND_ACC_USER_ARG_INFO flag was set.

Closes GH-19022
2025-12-15 16:50:49 +01:00
Ilija Tovilo
55c8d4a7e3 Merge branch 'PHP-8.5'
* PHP-8.5:
  Fix dumping function signature with dynamic class const lookup default argument
2025-12-08 16:20:04 +01:00
Ilija Tovilo
e66e9059df Merge branch 'PHP-8.4' into PHP-8.5
* PHP-8.4:
  Fix dumping function signature with dynamic class const lookup default argument
2025-12-08 16:19:53 +01:00
Ilija Tovilo
61eca669d9 Merge branch 'PHP-8.3' into PHP-8.4
* PHP-8.3:
  Fix dumping function signature with dynamic class const lookup default argument
2025-12-08 16:19:35 +01:00
Ilija Tovilo
26c0cbd93c Fix dumping function signature with dynamic class const lookup default argument
Fixes OSS-Fuzz #465488618
Closes GH-20651
2025-12-08 16:19:06 +01:00
Tim Düsterhus
7c9c39584c zend_inheritance: Improve formatting of return-by-ref & in zend_get_function_declaration() (#20104)
The space after `&` made it look like the `&` was not part of the signature,
possibly leading to confusion why the two signatures are incompatible without
carefully reading the message.
2025-10-19 17:37:38 +02:00
Gina Peter Banyard
39d6bc1716 Mark zend_visibility_string as returning a const char* (#19951)
This is because the char* returned is immutable and should not be modified.
2025-09-25 10:28:13 +01:00
Tim Düsterhus
c9b175992c Zend: Use true / false instead of 1 / 0 for bool parameters
Changes done with Coccinelle:

    @r1@
    identifier F;
    identifier p;
    typedef bool;
    parameter list [n1] PL1;
    parameter list [n2] PL2;
    @@

    F(PL1, bool p, PL2) {
    ...
    }

    @r2@
    identifier r1.F;
    expression list [r1.n1] EL1;
    expression list [r1.n2] EL2;
    @@

    F(EL1,
    (
    - 1
    + true
    |
    - 0
    + false
    )
    , EL2)
2025-09-24 18:51:40 +02:00
Tim Düsterhus
ef1b5ae61b Zend: Use return true / return false for functions returning bool
Changes done with Coccinelle:

    @r1@
    identifier fn;
    typedef bool;
    symbol false;
    symbol true;
    @@

    bool fn ( ... )
    {
    <...
    return
    (
    - 0
    + false
    |
    - 1
    + true
    )
    ;
    ...>
    }

Coccinelle patch sourced from
torvalds/linux@46b5c9b856.
2025-09-24 18:51:40 +02:00
Tim Düsterhus
c32fbca874 Zend: Use true / false instead of 1 / 0 when assigning to bool
Changes done with Coccinelle:

    @@
    bool b;
    @@

    - b = 0
    + b = false

    @@
    bool b;
    @@

    - b = 1
    + b = true
2025-09-24 18:51:40 +02:00
Ilija Tovilo
5b8a5320df Tweak get/set-only hook error messages
Fixes GH-19845
Closes GH-19916
2025-09-23 23:51:24 +02:00
Daniel Scherzer
34a6e86282 [RFC] Allow #[\Deprecated] on traits (#19045)
https://wiki.php.net/rfc/deprecated_traits
2025-09-05 12:30:50 -07:00
Alexandre Daubois
595abeef3f Fix GH-19548: remove ZEND_ACC_OVERRIDE on property inheritance only if it's not part of shared memory
Closes GH-19551
2025-08-22 16:16:54 +02:00
Jiří Pudil
38beb44176 [RFC] Extend #[\Override] to target properties (#19061)
RFC: https://wiki.php.net/rfc/override_properties

Co-authored-by: Tim Düsterhus <tim@bastelstu.be>
2025-08-12 15:18:50 +02:00
Arnaud Le Blanc
7b3e68ff69 Fix error handling inconsistency with opcache
When opcache is enabled, error handling is altered in the following ways:

 * Errors emitted during compilation bypass the user-defined error handler
 * Exceptions emitted during class linking are turned into fatal errors

Changes here make the behavior consistent regardless of opcache being enabled or
not:

 * Errors emitted during compilation and class linking are always delayed and
   handled after compilation or class linking. During handling, user-defined
   error handlers are not bypassed. Fatal errors emitted during compilation or
   class linking cause any delayed errors to be handled immediately (without
   calling user-defined error handlers, as it would be unsafe).
 * Exceptions thrown by user-defined error handlers when handling class linking
   error are not promoted to fatal errors anymore and do not prevent linking.

Fixes GH-17422.
Closes GH-18541.
Closes GH-17627.

Co-authored-by: Tim Düsterhus <tim@bastelstu.be>
2025-07-27 11:01:49 +02:00
Ilija Tovilo
d20f4fca69 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix properties_info_table for abstract properties
2025-07-21 15:54:53 +02:00
Ilija Tovilo
c8cc23336d Fix properties_info_table for abstract properties
Fixes GH-19053
Closes GH-19140

Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
2025-07-21 15:54:24 +02:00
Niels Dossche
383aad8007 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix GH-18534: FPM exit code 70 with enabled opcache and hooked properties in traits
2025-05-19 19:22:16 +02:00
Niels Dossche
6b795f64a5 Fix GH-18534: FPM exit code 70 with enabled opcache and hooked properties in traits
The trait handling for property hooks in preloading did not exist, we
add a check to skip trait clones and we add the necessary code to update
the op arrays.

Closes GH-18586.
2025-05-19 19:21:53 +02:00
Niels Dossche
06738fc051 Remove ZEND_ACC_USE_GUARDS from hooks (#18587)
This is no longer necessary since the hooks amendments removed guards
for recursion.
2025-05-18 15:01:24 +02:00
Ilija Tovilo
03d2226f45 Fix self inheritance type checks for traits
Fixes GH-18295
Closes GH-18296
2025-04-22 17:52:43 +02:00
Gina Peter Banyard
71da944c82 Zend: Add MUTABLE zend_type foreach macros and const qualifiers
The motivation for this is that types should be considered immutable.
The only times this is not valid is during compilation, optimizations (opcache), or destruction.

Therefore the "normal" type foreach macros are marked to take const arguments and we add mutable version that say so in the name.
Thus add various const qualifiers to communicate intent.
2025-04-07 12:52:40 +01:00
Gina Peter Banyard
462b170a30 Zend/zend_inheritance: Use bool instead of uint32_t 2025-04-05 15:47:51 +01:00
Gina Peter Banyard
dcf664963f Zend/zend_inheritance: Add some const modifiers 2025-04-05 15:47:51 +01:00
Gina Peter Banyard
10c9e4decf Zend/zend_inheritance: Reduce scope of variables
Fix some types at the same time
2025-04-05 15:47:51 +01:00
Gina Peter Banyard
1304719aae Zend/zend_inheritance: Prevent variable shadowing 2025-04-05 15:47:51 +01:00
Ilija Tovilo
011795bcbe Bind traits before parent class
This more accurately matches the "copy & paste" semantics described in
the documentation. Abstract trait methods diverge from this behavior,
given that a parent method can satisfy trait methods used in the child.
In that case, the method is not copied, but the check is performed after
the parent has been bound.

Fixes GH-15753
Fixes GH-16198
Close GH-15878
2025-04-01 18:20:02 +02:00
Ilija Tovilo
8731c95b35 Make missing trait error recoverable
We were already handling NULL as a case, but seem to have forgotten to
pass the ZEND_FETCH_CLASS_EXCEPTION flag.

Also make "is not a trait" error recoverable, there's no reason why it
can't be.

Fixes GH-17959
Closes GH-17960
2025-03-12 16:19:58 +01:00
rekmixa
4f5136cf2e Allow substituting static for self in final classes
Fixes GH-17725
Closes GH-17724
2025-03-05 11:31:46 +01:00
Ilija Tovilo
949e10e4c1 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix circumvented added hooks in JIT
2025-02-26 21:26:39 +01:00
Ilija Tovilo
376e90fbf2 Fix circumvented added hooks in JIT
The following code poses a problem in the JIT:

```php
class A {
    public $prop = 1;
}

class B extends A {
    public $prop = 1 {
        get => parent::$prop::get() * 2;
    }
}

function test(A $a) {
    var_dump($a->prop);
}

test(new B);
```

The JIT would assume A::$prop in test() could be accessed directly
through OBJ_PROP_NUM(). However, since child classes can add new hooks
to existing properties, this assumption no longer holds.

To avoid introducing more JIT checks, a hooked property that overrides a
unhooked property now results in a separate zval slot that is used
instead of the parent slot. This causes the JIT to pick the slow path
due to an IS_UNDEF value in the parent slot.

zend_class_entry.properties_info_table poses a problem in that
zend_get_property_info_for_slot() and friends will be called using the
child slot, which does not store its property info, since the parent
slot already does. In this case, zend_get_property_info_for_slot() now
provides a fallback that will iterate all property infos to find the
correct one.

This also uncovered a bug (see Zend/tests/property_hooks/dump.phpt)
where the default value of a parent property would accidentally be
inherited by the child property.

Fixes GH-17376
Closes GH-17870
2025-02-26 21:26:00 +01:00
Ilija Tovilo
15c2477273 Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix accidentally inherited default value in overridden virtual properties
2025-02-26 21:17:49 +01:00
Ilija Tovilo
e0c69dde02 Fix accidentally inherited default value in overridden virtual properties
Discovered when working on GH-17376.
2025-02-26 21:16:58 +01:00
Ilija Tovilo
84d00ec58f Merge branch 'PHP-8.4'
* PHP-8.4:
  Fix property hook backing value access in multi-level inheritance
2025-02-26 20:49:15 +01:00
Ilija Tovilo
7a55116f12 Fix property hook backing value access in multi-level inheritance
Discovered by Niels when testing GH-17376.
2025-02-26 20:49:07 +01:00
Gina Peter Banyard
65d433161a Use new known "self" and "parent" zend_strings (#17766) 2025-02-12 15:30:55 +00:00