Commit Graph

2758 Commits

Author SHA1 Message Date
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
Nikita Popov
4a455c1484 Merge branch 'PHP-8.1'
* PHP-8.1:
  Allow constant folding bw_not on string
2021-11-11 09:50:25 +01:00
Nikita Popov
4df15e8245 Allow constant folding bw_not on string
This will not actually error.
2021-11-11 09:49:48 +01:00
Tyson Andre
2b1b384d9a Fix inconsistency in true/false/null constant resolution when opcache is not used (#7441)
Strangely, uses of eval and 'php -a' (or loading a file without opcache after a namespaced constant was declared)
will not treat non-FQ true/false/null as magic keywords, while compiled php required from a file would do that.

This may confuse people learning the language, and result in code loaded with
eval() behaving differently from the same snippet in a file loaded by require.

```
Interactive shell

php > define('foo\true', 'test');
php > namespace foo { var_dump(true); }
string(4) "test"
```

This will make the same session instead properly emit `bool(true);` like it
already would if running those statements in files when opcache was used.

(cherry picked from commit 4c48fd22d7)
2021-11-09 10:43:56 +01:00
Nikita Popov
2d38f701e0 Merge branch 'PHP-8.1'
* PHP-8.1:
  Don't implement Stringable on traits
2021-11-05 09:48:33 +01:00
Nikita Popov
4bdb271894 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Don't implement Stringable on traits
2021-11-05 09:48:28 +01:00
Nikita Popov
d478ae73b1 Don't implement Stringable on traits
Traits do not support interfaces, so we should not implement
Stringable on them.

Also check the __toString() return type in the same way other
magic methods do, otherwise we would now miss the check in the
trait case.
2021-11-05 09:42:58 +01:00
Dmitry Stogov
90b7bde615 Use more compact representation for packed arrays.
- for packed arrays we store just an array of zvals without keys.
- the elements of packed array are accessible throuf as ht->arPacked[i]
  instead of ht->arData[i]
- in addition to general ZEND_HASH_FOREACH_* macros, we introduced similar
  familied for packed (ZEND_HASH_PACKED_FORECH_*) and real hashes
  (ZEND_HASH_MAP_FOREACH_*)
- introduced an additional family of macros to access elements of array
  (packed or real hashes) ZEND_ARRAY_ELEMET_SIZE, ZEND_ARRAY_ELEMET_EX,
  ZEND_ARRAY_ELEMET, ZEND_ARRAY_NEXT_ELEMENT, ZEND_ARRAY_PREV_ELEMENT
- zend_hash_minmax() prototype was changed to compare only values

Because of smaller data set, this patch may show performance improvement
on some apps and benchmarks that use packed arrays. (~1% on PHP-Parser)

TODO:
    - sapi/phpdbg needs special support for packed arrays (WATCH_ON_BUCKET).
    - zend_hash_sort_ex() may require converting packed arrays to hash.
2021-11-03 15:18:26 +03:00
Nikita Popov
a899dc9d17 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix self-assign evaluation order for ASSIGN_DIM_OP
2021-11-01 09:52:19 +01:00
Nikita Popov
55aadc647b Fix self-assign evaluation order for ASSIGN_DIM_OP
For $ary[idx] op= $ary we should evaluate the RHS operand first,
otherwise we may create a reference-free recursive array. Use the
same handling we do for the normal $ary[idx] = $ary case.

Fixes oss-fuzz #40287.
2021-11-01 09:50:22 +01:00
Nikita Popov
16e9e666ba Encode string offset error reason in extended_value
For FETCH_DIM_W etc encode the context it is being used in
(dim, obj, ref or incdec) so we can throw an appropriate error
message for invalid string offset use, in a way that does not
require inspecting neighboring opcodes. The implementation is
similar to the flags used for FETCH_OBJ.

This means that we do not have to be careful about preserving
following opcodes during optimization.

Closes GH-7599.
2021-10-21 09:52:09 +02:00
Dmitry Stogov
ddaf64b56c Avoid non-immutable map_ptr indirection 2021-10-14 12:16:18 +03:00
Nikita Popov
780db4ea42 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fix incorrect access of AST_UNPACK
2021-10-12 17:17:49 +02:00
Nikita Popov
f555544faf Fix incorrect access of AST_UNPACK
list_is_keyed() did not take into account that there may be
AST_UNPACK elements. These would error lateron anyway, but still
produce an invalid access here.
2021-10-12 17:16:58 +02:00
Dmitry Stogov
084c9faf4d Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed assign coalesce. "$a[0] ??= $a" should evaluate the right $a first.
2021-10-05 20:34:57 +03:00
Dmitry Stogov
80aaeb9696 Fixed assign coalesce. "$a[0] ??= $a" should evaluate the right $a first. 2021-10-05 20:34:09 +03:00
Dmitry Stogov
69fb20f106 Fixed assign coalesce. "$a[0] ??= $a" should evaluate the right $a first. 2021-10-05 20:23:56 +03:00
Kamil Tekiela
10f102d790
Fix 'can not' in error messages 2021-10-05 09:51:58 +01:00
codinghuang
5bda4cd25a Support specifying start position in compile_string
Add additional zend_compile_position argument, which can be either
AT_SHEBANG, AT_OPEN_TAG or AFTER_OPEN_TAG. The previous behavior
corresponds to AFTER_OPEN_TAG.

Closes GH-7462.
2021-09-30 10:21:33 +02:00
Nikita Popov
c19977d054 Fix delayed early binding with optimization
It's possible for delayed early binding opcodes to get optimized
away if they are "unreachable". However, we still need to attempt
early binding for them. (In some cases we also corrupt the early
binding list outright during optimization, which is how I got here.)

Fix this by storing information about delayed early binding
independently of DECLARE_CLASS_DELAYED opcodes, so early binding is
performed even after the opcode has been dropped.
2021-09-29 18:00:20 +02:00
Nikita Popov
a7ae4926b0 Merge branch 'PHP-8.1'
* PHP-8.1:
  Convert exception during delayed autoload to fatal error
  The PHP-8.1 branch is now for 8.1.0RC4
2021-09-29 10:05:45 +02:00
Nikita Popov
c8fa477064 Convert exception during delayed autoload to fatal error
Same as with other exceptions during inheritance, convert those
thrown during delayed class loading into fatal errors. We can't
properly deal with such exceptions, as inheritance cannot be
gracefully aborted at this point.

Fixes oss-fuzz #39405.
2021-09-29 10:03:23 +02:00
Nikita Popov
1c178569b4 Merge branch 'PHP-8.1'
* PHP-8.1:
  Fixed bug #81465
2021-09-23 14:31:40 +02:00
Nikita Popov
a942b284e6 Fixed bug #81465
Make the error message for enum cases more technically correct.
2021-09-23 14:29:27 +02:00