Commit graph

2866 commits

Author SHA1 Message Date
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
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