Commit Graph

2841 Commits

Author SHA1 Message Date
Ilija Tovilo
80873d28b1
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix trailing if element JMP lineno
2023-07-05 21:04:45 +02:00
Ilija Tovilo
a5e89c5686
Fix trailing if element JMP lineno
Having this lineno on the same last compiled element can lead to an incorrectly
covered line number.

if (true) {
    if (false) {
        echo 'Never executed';
    }
} else {
}

The echo will be reported as covered because the JMP from the if (true) branch
to the end of the else branch has the same lineno as the echo.

This is lacking a test because zend_dump.c does not have access to
ctx->debug_level and I don't think it's worth adjusting all the cases.

Closes GH-11598
2023-07-05 21:04:11 +02:00
Tim Düsterhus
49ef6e209d
RFC: Add #[Override] attribute (#9836)
* Add #[Override] attribute

* Move #[\Override] tests into Zend/tests/attributes/override/

* Check `check_only` before removing `ZEND_ACC_OVERRIDE`

* NEWS/UPGRADING for #[\Override]
2023-06-29 20:23:53 +02:00
Ilija Tovilo
68ef3938f4
Fix missing "Optional parameter before required" deprecation on union null type
The check would only work for the ?type syntax, but not  type|null. Switch to a
check during type compilation instead.

Fixes GH-11488
Closes GH-11497
2023-06-28 20:45:43 +02:00
Ilija Tovilo
a94216dcb7
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix mis-compilation of by-reference nullsafe operator
2023-06-28 20:37:25 +02:00
Ilija Tovilo
54dfa86728
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix mis-compilation of by-reference nullsafe operator
2023-06-28 20:36:30 +02:00
Ilija Tovilo
dc73b73f8b
Fix mis-compilation of by-reference nullsafe operator
Fixes oss-fuzz #60011
Closes GH-11540

Co-authored-by: Dmitry Stogov <dmitry@zend.com>
Co-authored-by: Niels Dossche <7771979+nielsdos@users.noreply.github.com>
2023-06-28 20:35:29 +02:00
Ilija Tovilo
fae42c8bd8
Fix assertion violation for invalid class const objects in const expressions (#11458)
Fixes oss-fuzz #59764
2023-06-21 14:59:05 +02:00
George Peter Banyard
d5ad75108e
More usage of known zend_str instead of C string (#11381) 2023-06-08 13:03:29 +01:00
Niels Dossche
79d024ac0e
Allow final modifier when using a method from a trait (#11394)
Fixes GH-11388.

Following https://wiki.php.net/rfc/horizontalreuse which introduced traits,
this should be allowed.
The implementation was refactored in 3f8c729. That commit is the first time
the "final" check appears AFAICT, but no reason was given for why. That
commit seems to have landed in 5.4.11 and the NEWS for that version doesn't
seem to mention something relevant to the behaviour change.
This patch removes the restriction of the final modifier.

Closes GH-11394.
2023-06-07 23:53:21 +02:00
Ilija Tovilo
fbe6696d49 Revert "Use zend_ast_apply in zend_eval_const_expr (#11261)"
This reverts commit 1c733c8bbc.

Fixes GH-11320
2023-05-26 12:15:01 +02:00
Ilija Tovilo
0b1d750d91
Allow arbitrary expressions in static variable initializer
Closes GH-9301
2023-05-24 20:17:31 +02:00
Ilija Tovilo
1c733c8bbc
Use zend_ast_apply in zend_eval_const_expr (#11261)
Supporting new constant expressions requires remembering to add them to
zend_eval_const_expr, even if it only evalutes its children. This is routinely
forgotten, at least by me. Use zend_ast_apply to solve this generically.
2023-05-24 16:35:37 +02:00
Nikita Popov
c230aa9be3 Correctly handle multiple constants in typed declaration
While here also fix AST printing support.
2023-05-21 14:17:01 +01:00
Ilija Tovilo
0600f513b3
Implement delayed early binding for classes without parents
Normally, we add classes without parents (and no interfaces or traits) directly
to the class map, early binding the class. However, if the same class has
already been registered, we would instead just add a ZEND_DECLARE_CLASS
instruction and let the handler throw a duplicate class declaration exception.

However, with opcache, if on the next request the files are included in the
opposite order, we won't perform early binding. To fix this, create a
ZEND_DECLARE_CLASS_DELAYED instruction instead and handle classes without
parents accordingly, skipping any linking for classes that are already linked in
delayed early binding.

Fixes GH-8846
2023-05-15 10:25:33 +02:00
Ilija Tovilo
4f74e8672c
Merge branch 'PHP-8.2'
* PHP-8.2:
  Allow aliasing namespaces containing reserved class names
2023-04-30 13:44:58 +02:00
Ilija Tovilo
5ad6571a21
Allow aliasing namespaces containing reserved class names
This reverts commit b9f7123c5e.

Fixes GH-11152
Closes GH-11153
2023-04-30 13:44:34 +02: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
Ilija Tovilo
c4a1100f19
Fix unevaluated rhs of class constant fetch in constant expression (#11047)
Fixes oss-fuzz #57821
2023-04-10 16:41:43 +02:00
Niels Dossche
3ab6e76ed8 Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-10983: State-dependant segfault in ReflectionObject::getProperties
  Fix GH-10990: mail() throws TypeError after iterating over $additional_headers array by reference
  Fix GH-8841: php-cli core dump calling a badly formed function
2023-04-01 20:23:57 +02:00
Niels Dossche
0d12b3db64 Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10990: mail() throws TypeError after iterating over $additional_headers array by reference
  Fix GH-8841: php-cli core dump calling a badly formed function
2023-04-01 20:04:48 +02:00
Niels Dossche
cf9b030a57 Fix GH-8841: php-cli core dump calling a badly formed function
It's actually not php-cli specific, nor SAPI specific.
We should delay the registration of the function into the function table
until after the compilation was successful, otherwise the function is
mistakingly registered and a NULL dereference will happen when trying to
call it.

I based my test of Nikita's test, so credits to him for the test:
https://github.com/php/php-src/pull/8933#issuecomment-1259881008

Closes GH-10989.
2023-04-01 19:43:09 +02:00
Ilija Tovilo
9d5f2f1343
Use new ZSTR_INIT_LITERAL macro (#10879) 2023-03-20 16:19:05 +01:00
Ilija Tovilo
3a602d235c
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-10570: Assertion `(key)->h != 0 && "Hash must be known"' failed.
2023-02-24 20:42:00 +01:00
Ilija Tovilo
9b10b65e2b
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix GH-10570: Assertion `(key)->h != 0 && "Hash must be known"' failed.
2023-02-24 20:41:40 +01:00
Niels Dossche
b9a5bfc355
Fix GH-10570: Assertion `(key)->h != 0 && "Hash must be known"' failed.
Fixes GH-10570, see GH-10570 for analysis.

Closes GH-10572
2023-02-24 20:40:29 +01: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
Max Kellermann
bb07e20203
Two enums instead of preprocessor macros (#10617)
* Zend/zend_compile: convert `memoize_mode` macros to enum

* Zend/zend_stack: convert `ZEND_STACK_APPLY_*` macros to enum
2023-02-21 15:34:33 +01:00
Max Kellermann
49c1e6eb33
Make various pointers const in Zend/ (#10608)
* Zend/zend_operators: pass const pointers to zend_is_identical()

* Zend/zend_operators: pass const pointers to zend_get_{long,double}()

* Zend/Optimizer/sccp: make pointers const

* Zend/Optimizer/scdf: make pointers const

* Zend/Optimizer/zend_worklist: make pointers const

* Zend/Optimizer/zend_optimizer: make pointers const

* Zend/zend_compile: make pointers const
2023-02-20 14:00:59 +00:00
Niels Dossche
e52684ea8a
Fix GH-10377: Unable to have an anonymous readonly class
This fixes the oversight that an anonymous class should be able to be
readonly. Other identifiers such as final and abstract do not make
sense. As we still want nice errors for when users try to use these
modifiers, or use multiple modifiers, we introduce a new function
zend_add_anonymous_class_modifier that will perform verification for
anonymous class modifiers, just like zend_add_class_modifier does for
non-anonymous classes.

Closes GH-10381
2023-02-20 13:32:26 +01:00
Ilija Tovilo
fb670f2b80
Move setting of CG(zend_lineno)
This way it will also work for zend_ast_create_zval
2023-02-02 19:55:23 +01:00
Ilija Tovilo
848a6e5035
Fix incorrect line number of constant in constant expression
Fixes GH-10356
2023-02-02 19:51:54 +01:00
Ilija Tovilo
35a36b13e5
Fix comp-time and constant evaluation of dynamic class constant fetch
Fixes GH-10486
Fixes oss-fuzz #55436
Fixes oss-fuzz #55472
Closes GH-10487
2023-02-02 19:18:17 +01:00
Ilija Tovilo
02bd52b5a8
Implement dynamic class const fetch
https://wiki.php.net/rfc/dynamic_class_constant_fetch

Closes GH-9793
2023-01-26 16:46:34 +01: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
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
72dd94e1c6 Zend/zend_compile: include cleanup 2023-01-15 15:07:58 +00:00
Arnaud Le Blanc
a11c8a3039
Limit stack size (#9104) 2022-12-16 17:44:26 +01:00
Jorg Adam Sowa
77ee92a50c
Remove unnecessary usage of CONST_CS
Closes GH-9685.
2022-11-28 17:12:07 +01:00
Ilija Tovilo
adfdfb2e1e
Improvements in modifier parsing (#9926)
Use a shared non-terminal for all class modifiers. This avoids conflicts when
adding modifiers that are only valid for certain targets. This change is
necessary for asymmetric visibility but might be useful for other future
additions.

Closes GH-9926
2022-11-17 16:20:27 +01:00
Bob Weinand
cda97e7a5a Merge branch 'PHP-8.2' 2022-11-09 14:19:54 +01:00
Bob Weinand
6bd8f40291 Move observer_declared_function_notify until after pass_two()
For early observing, there already exists a op_array_ctor hook on zend_extension.
However the goal of the declared_function observer is noting the time when a fully defined function starts existing in the function_tables.
This also prevents the observer being called in case there were compilation errors.

Ultimately, this now gives a consistent behaviour with respect to how it works when opcache is enabled:
- pass_two is done, opcodes and flags are all finalized.
- similarly class_linked notifications also only happen once the class is actually finalized.
- any extension wanting to delay the observer call may add the ZEND_COMPILE_IGNORE_OBSERVER compiler_option, then call it itself.
2022-11-09 13:15:41 +01:00
Ilija Tovilo
28dd6006c0
Merge branch 'PHP-8.2'
* PHP-8.2:
  Properly deal with internal attributes used on promoted properties.
2022-11-03 14:29:44 +01:00
Martin Schröder
fdd088fc81
Properly deal with internal attributes used on promoted properties.
Closes GH-9661
2022-11-03 14:29:22 +01:00
George Peter Banyard
76b8bace07
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix OpCache build after 0b0259a418
2022-10-24 15:18:03 +01:00
George Peter Banyard
cb3adf351d
Fix OpCache build after 0b0259a418
The intersection type needs to be marked as being allocated on the arena otherwise zend_persist_type() tries to free it and corrupts the Zend MM Heap

Also we only need to allocate the space for a list of size 1 and not the whole length of the intersection type
2022-10-24 15:17:26 +01:00
George Peter Banyard
6e8f2ba6b8
Merge branch 'PHP-8.2'
* PHP-8.2:
  Revert 01eb06a0de
  Convert Implicitly nullable pure intersection types to DNF
2022-10-24 11:42:41 +01:00
George Peter Banyard
8c2df899d0
Revert 01eb06a0de
We do not need this shim anymore since it is converted to a proper DNF type at compile time
2022-10-24 11:41:42 +01:00
George Peter Banyard
0b0259a418
Convert Implicitly nullable pure intersection types to DNF
If we don't then Reflection would give us a ReflectionIntersectionType even if the type is currently displayed as (X&Y)|null
2022-10-24 11:39:54 +01:00
Dmitry Stogov
5a68d991ad Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix memory leak
2022-10-17 15:09:33 +03:00