Commit graph

2881 commits

Author SHA1 Message Date
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
George Peter Banyard
b40ae80804
Convert iterable into an internal alias for Traversable|array (#7309)
This does a compile time transformation of ``iterable`` into ``Traversable|array`` which simplifies some of the LSP variance handling.

The arginfo generation script from stubs is updated to produce a union type when it encounters the type ``iterable``
Extension functions which do not regenerate the arginfo, or write them manually are still supported by mimicking the compile time transformation while registering the function.

Type Reflection is preserved for single ``iterable`` (and ``?iterable``) to produce a ReflectionNamedType with name ``iterable``, however usage of ``iterable`` in union types will be converted to ``array|Traversable``
2022-06-07 13:35:34 +01:00
Máté Kocsis
a3f8bb33cd
Remove special case for the error message of static properties in readonly classes 2022-05-23 09:44:40 +02:00
Derick Rethans
852e6b957b Merge branch 'PHP-8.1' 2022-05-20 10:52:58 +01:00
Derick Rethans
9a195054cc Merge branch 'PHP-8.0' into PHP-8.1 2022-05-20 10:52:54 +01:00
Derick Rethans
c06e1abbaa Emit EXT_STMT for each 'elseif' clause 2022-05-20 10:51:58 +01:00
Máté Kocsis
7850c10389
Add support for readonly classes (#7305)
RFC: https://wiki.php.net/rfc/readonly_classes
2022-05-16 20:40:23 +02:00
Ilija Tovilo
9a90bd7054
Deprecate ${} string interpolation
https://wiki.php.net/rfc/deprecate_dollar_brace_string_interpolation
2022-05-05 10:14:56 +02:00
Nikita Popov
460bbc8ebe Add clarifying comment for SEND_VAL usage
This confused me for a bit, because we're using SEND_VAL here to
potentially perform a by-ref SEND, while it is usually used for
by-val SENDs.
2022-04-24 18:21:32 +02:00
Nikita Popov
74c0edefe7 Remove unnecessary abstract function check in zend_get_call_op()
Abstract functions are now handled in the INIT stage, they do not
affect DO opcodes anymore.

Also add a check for another precondition, namely that the function
is not a trampoline.
2022-04-17 18:07:52 +02:00
George Peter Banyard
6039c07a3a
Allow `null and false` as standalone types (#7546)
RFC: https://wiki.php.net/rfc/null-standalone-type

Also a drive-by consistency fix for error messages.
2022-04-08 17:23:52 +01:00
Max Kellermann
b9e895bca0
Replace memcmp() with zend_string functions (#8216)
* ext/oci8: use zend_string_equals()

Eliminate duplicate code.

* main/php_variables: use zend_string_equals_literal()

Eliminate duplicate code.

* Zend/zend_string: add zend_string_equals_cstr()

Allows eliminating duplicate code.

* Zend, ext/{opcache,standard}, main/output: use zend_string_equals_cstr()

Eliminate duplicate code.

* Zend/zend_string: add zend_string_starts_with()

* ext/{opcache,phar,spl,standard}: use zend_string_starts_with()

This adds missing length checks to several callers, e.g. in
cache_script_in_shared_memory().  This is important when the
zend_string is shorter than the string parameter, when memcmp()
happens to check backwards; this can result in an out-of-bounds memory
access.
2022-03-31 16:27:58 +02:00
Dmitry Stogov
91734fc579 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix crush after compilation of nullsafe operator introduced in 307e476e86
2021-12-09 18:19:38 +03:00
Dmitry Stogov
7e080183f4 Fix crush after compilation of nullsafe operator introduced in 307e476e86
Now we flush only delayed opcodes realted to this nullsafe operator.

Fixes oss-fuzz #42152
2021-12-09 18:15:47 +03:00
Ilija Tovilo
051b3967a9
Merge branch 'PHP-8.1'
* PHP-8.1:
  Improve final/abstract methods in interfaces error messages
2021-12-05 23:48:26 +01:00
Ilija Tovilo
b991ce9c1e
Improve final/abstract methods in interfaces error messages
Closes #81683
Closes GH-7722
2021-12-05 23:10:07 +01:00
Ilija Tovilo
66af53cab8
Merge branch 'PHP-8.1' 2021-12-05 18:33:10 +01:00
Ilija Tovilo
dab6226cbe
Fix invalid opcode for ??= on $GLOBALS
Closes #81684
Closes GH-7717
2021-12-05 18:25:02 +01:00
Tyson Andre
024d5f4b63 Cache method overrides of ArrayAccess in zend_class_entry
Previously, code such as subclasses of SplFixedArray would check for method
overrides when instantiating the objects.

This optimization was mentioned as a followup to GH-6552
2021-12-04 11:35:38 -05:00
Dmitry Stogov
dbde68f31e Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed bug #81216 (Nullsafe operator leaks dynamic property name)
2021-12-04 18:05:15 +03:00
Dmitry Stogov
307e476e86 Fixed bug #81216 (Nullsafe operator leaks dynamic property name)
Fixes oss-fuzz #38542
2021-12-04 18:04:24 +03:00