Commit Graph

2801 Commits

Author SHA1 Message Date
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
Dmitry Stogov
eecbb60db6 Fix memory leak
Fixes oss-fuzz #52479
2022-10-17 15:08:21 +03:00
George Peter Banyard
a593a456f1
Merge branch 'PHP-8.2'
* PHP-8.2:
  Follow-up fix for GH-9655
2022-10-04 14:25:57 +01:00
George Peter Banyard
01eb06a0de
Follow-up fix for GH-9655
Type needs to be rendered as a DNF type and not X&Y|null
2022-10-04 14:24:51 +01:00
George Peter Banyard
8f63cc7b8b
Merge branch 'PHP-8.2'
* PHP-8.2:
  Fix GH-9655: Allow pure intersection types to be implicitly nullable
2022-10-03 11:03:31 +01:00
HypeMC
279ffdb598
Fix GH-9655: Allow pure intersection types to be implicitly nullable
Closes GH-9659
2022-10-03 11:02:52 +01:00
George Peter Banyard
bb79ef775b
Fix GH-9556 "iterable" alias "array|Traversable" breaks PHP 8.1 code
Closes GH-9558
2022-09-30 12:50:45 +01:00
George Peter Banyard
235e152e1a
Move object/class redundancy check into union type handling
As such a redundancy can only happen for union types
2022-09-30 12:50:45 +01:00
George Peter Banyard
c801076d8b
Fix GH-9556 "iterable" alias "array|Traversable" breaks PHP 8.1 code
Closes GH-9558
2022-09-30 12:49:15 +01:00
George Peter Banyard
74ae498a4b
Move object/class redundancy check into union type handling
As such a redundancy can only happen for union types
2022-09-30 12:48:56 +01:00
Ilija Tovilo
ed202b2a50
Merge branch 'PHP-8.2'
* PHP-8.2:
  Don't throw CompileError after parsing
2022-09-14 23:06:05 +02:00
Ilija Tovilo
7e860eaef0
Don't throw CompileError after parsing
Aborting parsing is not safe, a fatal error is necessary.

See b9f7123c5e
2022-09-14 23:05:41 +02:00
Bob Weinand
5a0b68bed7 Revert "Store default object handlers alongside the class entry"
This reverts commit 9e6eab3c13.

Reverted along a01dd9feda.
2022-09-14 11:18:14 +02:00
George Peter Banyard
6c4d24e4f0 Update cache slot size calculation in compact_literals.c 2022-09-10 13:20:59 +01:00
George Peter Banyard
9286101da4 Fix GH-9516: (A&B)|D as a param should allow AB or D. Not just A.
The issue was that we didn't compute enough cache slots for DNF types.
Nor progressed throught the CE's in the cache slot, meaning we were only checking if the value passed
satisfied the first type of the nested intersection type.
2022-09-10 11:34:32 +01:00
Ilija Tovilo
580c29e1a2
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix lsp error in eval'd code referring to incorrect class for static type
2022-09-08 10:54:02 +02:00
Ilija Tovilo
15ee9d2686
Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix lsp error in eval'd code referring to incorrect class for static type
2022-09-08 10:53:45 +02:00
Ilija Tovilo
d5373eac46
Fix lsp error in eval'd code referring to incorrect class for static type
Fixes GH-9407
Closes GH-9471
2022-09-08 10:52:27 +02:00
Ilija Tovilo
d36874d002
Merge branch 'PHP-8.1' into PHP-8.2
* PHP-8.1:
  Fix class name FQN when AST dumping new and class const
2022-09-02 08:58:27 +02:00
Ilija Tovilo
2cfb028e22
Fix class name FQN when AST dumping new and class const
Fixes GH-9447
Closes GH-9462
2022-09-02 08:57:26 +02:00
Bob Weinand
9e6eab3c13 Store default object handlers alongside the class entry
Object handlers being separate from class entries is a legacy inherited from PHP 5. Today it has little benefit to keep them separate: in fact, accessing object handlers usually requires not-so-safe hacks.
While it is possible to swap handlers in a custom installed create_object handler, this mostly is tedious, as well as it requires allocating the object handlers struct at runtime, possibly caching it etc..

This allows extensions, which intend to observe other classes to install their own class handlers.
The life cycle of internal classes may now be simply observed by swapping the class handlers in post_startup stage.
The life cycle of userland classes may be observed by iterating over the new classes in zend_compile_file and zend_compile_string and then swapping their handlers.

In general, this would also be a first step in directly tying the object handlers to classes. Especially given that I am not aware of any case where the object handlers would be different between various instances of a given class.

Signed-off-by: Bob Weinand <bobwei9@hotmail.com>
2022-08-31 16:45:27 +02:00
George Peter Banyard
b9f7123c5e
Check at compile time that a built-in class is not being aliased (#9402)
If one tries to use such an alias as a type declaration the following error would be raised:
Fatal error: Cannot use 'int' as class name as it is reserved
2022-08-23 22:34:02 +01: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
Ollie Read
9b984f52ea
Enum error message consistency (#9350) 2022-08-23 13:32:34 +02:00
Dmitry Stogov
a44fb09620 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix memory leaks
2022-08-22 17:54:36 +03:00
Dmitry Stogov
5bab9e94fd Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix memory leaks
2022-08-22 17:47:43 +03:00
Dmitry Stogov
73c2d79fc5 Fix memory leaks
Fixes oss-fuzz #50078
2022-08-22 17:47:07 +03:00
Tyson Andre
6a50af2604
Make "{$g{'h'}}" emit fatal error and no incorrect deprecation notice in 8.2 (#9264)
The ast node flag constants ZEND_DIM_ALTERNATIVE_SYNTAX and
ZEND_ENCAPS_VAR_DOLLAR_CURLY_VAR_VAR node have identical values (1<<1),
causing a deprecation notice to be incorrectly emitted before the fatal error
for unsupported syntax.

Fixes GH-9263

Explicitly check for AST_VAR/AST_DIM kind for future compatibility

`AST_PROP`/`AST_METHOD_CALL` and nullsafe variants can also be found in
encapsulated strings - currently they have no flags but they may have flags in
the future. This also clarifies that this deprecation warning can only happen
for AST_VAR/AST_DIM nodes for certain `attr` values.
2022-08-08 19:41:32 -04:00
sji
3b62d66098
Implement constants in traits (#8888)
RFC: https://wiki.php.net/rfc/constants_in_traits
2022-08-04 20:08:40 +01:00
Ilija Tovilo
3663f7661a
DIM on null in const expr should emit warning 2022-08-04 11:24:16 +02:00
Ilija Tovilo
7b43d819c8
Also fix ?-> on magic consts in const expressions
Fixes GH-9136
Fixes GH-9138
2022-08-03 23:40:06 +02: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
f957e3e7f1
Fix arrow function with never return type
Fixes GH-7900
Closes GH-9103
2022-07-29 12:25:09 +02:00
Ilija Tovilo
966d22b1bd
Fix property fetch on magic constants in constant expressions
Closes GH-9136
Closes GH-9138
Closes GH-9172
2022-07-28 14:14:11 +02:00
Ilija Tovilo
7aadbcb8f4
GH-8344 Fetch properties of enums in const expressions 2022-07-18 23:52:28 +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
Ilija Tovilo
bc03deec27 Fix magic constants in backed enum values
Fix GH-8777
2022-06-23 19:17:44 +02:00
Ilija Tovilo
44cd74b624
Fix lineno in backtrace of multi-line function calls
Closes GH-8810
Closes GH-8818
2022-06-23 16:10:32 +02:00
George Peter Banyard
0ae6a67550
Add true as a type (#8326)
RFC: https://wiki.php.net/rfc/true-type
2022-06-12 23:28:19 +01: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
Ilija Tovilo
5a855ee8d6
Fix GH-8661: Nullsafe in coalesce triggers undefined variable warning
Closes GH-8690
2022-06-12 21:52:14 +02:00