Commit Graph

4249 Commits

Author SHA1 Message Date
Nikita Popov
fabcc9a350 Fix long-term shutdown/tick fci/fcc storage
Normally incrementing the refcount on just function_name is
sufficient. However, if the callable is of the form 'X::y' inside
an instance method, this will capture $this in fcc.object, which
also needs to be retained.

The fci_addref/fci_release helpers should likely be exported as
a general API, as we may have this problem in other places as
well.

Fixes oss-fuzz #39778.
2021-10-11 12:19:29 +02:00
Nikita Popov
a4b209fdcf Make weak ref notify robust against bailout
First drop it from EG(weakrefs), as the weakref_unref operation
may call a destructor, which may bail out.

Fixes oss-fuzz #39718.
2021-10-08 16:42:43 +02:00
Nikita Popov
bd3e536383 Fixed bug #81514
Objects reuse the GC_PERSISTENT flag as IS_OBJ_WEAKLY_REFERENCED,
which we did not account for in ZVAL_COPY_OR_DUP. To make things
worse the incorrect zval_copy_ctor_func() invocation silently did
nothing. To avoid that, add an assertion that it should only be
called with arrays and strings (unlike the normal zval_copy_ctor()
which can be safely called on any zval).
2021-10-08 10:31:24 +02: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
Nikita Popov
02c5f7f927 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix duplicate undef warning in assign_dim_op
2021-10-05 15:51:30 +02:00
Nikita Popov
11a9b036a8 Fix duplicate undef warning in assign_dim_op
In case of auto-vivification we were fetching dim twice and as
such also emitting the undef var warning twice.
2021-10-05 15:51:11 +02:00
Nikita Popov
8360e9d6d1 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix COPY_TMP live range construction after optimization
2021-10-05 11:28:41 +02:00
Nikita Popov
bbd3f714d7 Fix COPY_TMP live range construction after optimization
If we optimize the FREE away, we should switch to constructing
a normal live range, rather than a split live range.

Fixes oss-fuzz #39548.
2021-10-05 11:28:16 +02:00
Nikita Popov
493c91c742 Start new block after loop free
In the attached test case we ended up not updating a leftover
MATCH jump in the unreachable_free block. There's different ways
this can be addressed, but in this case we can just make sure that
a new block is started after the loop free, which will allow it
to be dropped as unreachable. We only need to retain the free
itself for live-range reconstruction.

Fixes oss-fuzz #39516.
2021-10-04 16:59:46 +02:00
Nikita Popov
02244d5ee6 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Create reference wrappers in SEND_UNPACK if necessary
2021-09-30 14:56:44 +02:00
Nikita Popov
e11faad233 Create reference wrappers in SEND_UNPACK if necessary
Even if we can't actually pass by reference, we still need to
create the REFERENCE wrapper to satisfy the calling convention.
The particular test case would crash with JIT, because the existence
of the reference was assumed.

Fixes oss-fuzz #39440.
2021-09-30 14:55:48 +02:00
Nikita Popov
5cdbfa897c Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix cache slot assignment for ASSIGN_OBJ_OP
2021-09-30 14:34:50 +02:00
Nikita Popov
d0860f67ca Fix cache slot assignment for ASSIGN_OBJ_OP
ASSIGN_OBJ_OP stores the cache slot in OP_DATA, so this ended up
overwriting the binop opcode instread.
2021-09-30 14:34:12 +02:00
Nikita Popov
6768aae40a Disable JIT in test replacing zend_execute_ex 2021-09-29 20:49:27 +02:00
Nikita Popov
018ddba9ae Fix backtraces with overridden zend_execute_ex 2021-09-29 16:25:00 +02:00
Nikita Popov
944d653b3d Fix inference for INIT_ARRAY with illegal offset type
Extract assign_dim_array_result_type() helper that can be reused
for INIT_ARRAY and implements all this logic correctly.

Fixes oss-fuzz 5156868775870464.
2021-09-29 11:09:04 +02:00
Nikita Popov
9346da8964 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Handle throwing destructor in BIND_STATIC
2021-09-29 10:17:22 +02:00
Nikita Popov
ec54ffad1e Handle throwing destructor in BIND_STATIC
Fixes oss-fuzz #39406.
2021-09-29 10:17:05 +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
69eb6e04a7 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix ASSIGN_DIM result inference with typed refs
  Remove outdated code in ASSIGN_DIM type inference
2021-09-28 14:14:29 +02:00
Nikita Popov
1bb7ee3207 Fix ASSIGN_DIM result inference with typed refs
Same issue as with ASSIGN. Also make the handling for ASSIGN more
precise, we can only have conversions between scalar values.
2021-09-28 14:14:01 +02:00
Nikita Popov
2b71df71a1 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix type inference and SCCP with typed references
2021-09-28 12:59:24 +02:00
Nikita Popov
d8c2ff6486 Fix type inference and SCCP with typed references
We can't assume that the return value will be the same as the RHS
if typed references are involved.
2021-09-28 12:59:00 +02:00
Nikita Popov
1e4a9a4999 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix block marking for two arm math
2021-09-28 10:38:22 +02:00
Nikita Popov
17d6efc729 Fix block marking for two arm math
This would end up taking the successors_count=2 case, even though
we need to treat SWITCH and MATCH differently. This incorrectly
marked a block as FOLLOW, resulting in incorrect block pass
optimization.

Fixes oss-fuzz #39380.
2021-09-28 10:37:54 +02:00
Nikita Popov
0015fc9a8e Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix relative offsets when copying JMPZNZ
2021-09-27 16:20:04 +02:00
Nikita Popov
7d483418e2 Fix relative offsets when copying JMPZNZ
This was doing a plain copy of JMPZNZ, even though it encodes
offsets relative to the opline. As such, the offsets would be
relative to target, while they should be relative to opline.
Fix this by recomputing them.

Fixes oss-fuzz #39295.
2021-09-27 16:18:40 +02:00
Nikita Popov
b86fdf84f0 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Start block at loop var free
2021-09-27 11:58:53 +02:00
Nikita Popov
823888c472 Start block at loop var free
This ensures that code directly before the loop var free is
separated out (and will generally be eliminated as unreachable).
This fixes some assumptions we have that unreachable loop var free
blocks start with the loop var free.

Fixes oss-fuzz #39395.
2021-09-27 11:56:37 +02:00
Nikita Popov
b7ec15f7fe Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix DCE of unreachable phi in cycle
2021-09-27 11:26:56 +02:00
Nikita Popov
ddf8910237 Fix DCE of unreachable phi in cycle
We can't remove a trivial phi of the form x = phi(x), because we
don't have a replacement value. We could drop the whole block
though. SCCP would normally do this, but in this particular case
we only determine non-reachability based on type information.

Fixes oss-fuzz #39316.
2021-09-27 11:26:31 +02:00
Nikita Popov
d5e80c1c0c Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Handle pi nodes in replace_predecessor
2021-09-27 10:48:23 +02:00
Nikita Popov
038bc27787 Handle pi nodes in replace_predecessor
If we're removing a predecessor because it already exists during
replacement, we should also drop pi nodes for that predecessor.

Fixes oss-fuzz #39276.
2021-09-27 10:47:47 +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
Nikita Popov
3991483727 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Bail on exception during delayed autoload
2021-09-23 12:46:56 +02:00
Nikita Popov
be8217368b Bail on exception during delayed autoload
We shouldn't try to load further classes if one autoload throws.

This fixes oss-fuzz #38881, though I believe there are still two
deeper issues here: 1) Why do we allow autoloading with an active
exception? 2) Exception save & restore should probably also save
and restore the exception opline.
2021-09-23 12:46:39 +02:00
Nikita Popov
c9762be566 Don't treat expression exit as terminator
Same as with throw expressions, this may remove later temporary
consuming instructions and thus eliminate live ranges, resulting
in a memory leak. We make use of the same hack and don't consider
exit a terminator if used in an expression context.
2021-09-23 10:26:07 +02:00
Nikita Popov
92f808b8bc Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Fix SEND_USER with ref arg
2021-09-17 12:18:16 +02:00
Nikita Popov
01453a0af7 Fix SEND_USER with ref arg
Even though the input is not a reference (or not treated as such),
we still need to create a reference to satisfy the function
signature. Various code relies on reference arguments actually
being references. In this particular case, it would result in
a JIT crash.

The zend_call_function() implementation already handled this
correctly.
2021-09-17 12:17:33 +02:00
Nikita Popov
4796183958 Add missing scope check for readonly prop initialization
If the initializing assignment is an array append we will go through
the UNDEF codepath of get_property_ptr_ptr, which did not verify
that the initialization scope is valid.
2021-09-17 11:20:29 +02:00
Nikita Popov
260d2acdb4 Fix memory leak in array unpack with refcounted numeric string key 2021-09-14 12:14:12 +02:00
Nikita Popov
76348f3378
Allow using readonly as function name
Don't treat "readonly" as a keyword if followed by "(". This
allows using it as a global function name. In particular, this
function has been used by WordPress.

This does not allow other uses of "readonly", in particular it
cannot be used as a class name, unlike "enum". The reason is that
we'd still have to recognize it as a keyword when using in a type
position:

    class Test {
        public ReadOnly $foo;
    }

This should now be interpreted as a readonly property, not as a
read-write property with type `ReadOnly`. As such, a class with
name `ReadOnly`, while unambiguous in most other circumstances,
would not be usable as property or parameter type. For that
reason, we do not support it at all.
2021-09-13 08:50:32 +02:00
Nikita Popov
f6daf83e75 Merge branch 'PHP-8.0' into PHP-8.1
* PHP-8.0:
  Check that POST_INC/DEC has use in DFA optimization
2021-09-09 15:50:04 +02:00
Nikita Popov
5cae6b9b0d Check that POST_INC/DEC has use in DFA optimization
We'd have usually converted it into a PRE_INC if there is no use,
but that's not guaranteed. If there is no use at this point, make
sure we don't try to use the sentinel value.
2021-09-09 15:48:51 +02:00
Tyson Andre
4c48fd22d7
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.
2021-09-03 08:42:36 -04:00
Nikita Popov
3eeeeeb104 Fully qualify ReturnTypeWillChange in deprecation message
When adding the #[ReturnTypeWillChange] attribute in namespaced
code, you also need to use ReturnTypeWillChange, otherwise it
will be silently ignored and may result in confusion. Change the
deprecation message to suggest #[\ReturnTypeWillChange], which
will always work.

Closes GH-7454.
2021-09-03 13:57:23 +02:00
Máté Kocsis
805f2b9803
Fix forgotten test 2021-09-02 17:44:52 +02:00
Nikita Popov
2cc47a04df Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix Closure::call() on internal method closure
2021-08-27 12:00:07 +02:00
Nikita Popov
2467f759f5 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix Closure::call() on internal method closure
2021-08-27 11:59:38 +02:00
Nikita Popov
eda9f5f740 Fix Closure::call() on internal method closure
In this case we should use the original internal handler. Otherwise
the trampoline will attempt to free the closure, but the function
being used is not actually part of a closure anymore.
2021-08-27 11:58:13 +02:00
Nikita Popov
4fcf0db649 Fix use after free when rebinding __call closure
We would end up freeing the function name twice here, once for
the original closure, and once for the rebound one.

Rather than further special casing the zend_closure_call_magic
case, always addref the function_name for internal functions,
the same we do for userland functions. To compensate, we need to
release the original function name when creating from callable
or call frame.

Fixes oss-fuzz #37695.
2021-08-27 11:34:22 +02:00
Nikita Popov
b964d007e3 Fix AST print of first class callable in anon class expr
This will cause a compile error later, but the expression is
printed first.

Fixes oss-fuzz #37473.
2021-08-26 12:00:37 +02:00
Nikita Popov
a40ccd758c Fixed bug #81377
BP_VAR_UNSET should not result in undefined warnings.
2021-08-24 15:05:53 +02:00
Nikita Popov
8755976315 Fix arginfo/zpp consistency check for call_user_func from strict_types scope
This was using the wrong strict_types information. In this case the
call is performed with strict_types=0.
2021-08-16 12:11:39 +02:00
Michael Voříšek
3398efa597
Fix typo in enum test (#7368)
Fix typo in enum test and test create prop with typed enum.
2021-08-14 09:53:37 +02:00
Nikita Popov
a027247289 Fix message in test
Looks like I did not "git add" the message update.

Also drop the now dead ZEND_ENUM_PROPERTY_ERROR() macro while
here.
2021-08-13 17:01:16 +02:00
Nikita Popov
caefc6a507 Don't use custom object handlers for enum properties
Instead mark name/value as readonly and the class as
NO_DYNAMIC_PROPERTIES. This gives us the desired limitations
using native features.

In fact, this also fixes a bug where opcache cache slot merging
might result in a write to the name/value properties being
allowed. The readonly implementation handles this case correctly.
2021-08-13 16:44:39 +02:00
Nikita Popov
1c6df2dffd Fixed bug #81192
Normally the filename is the current filename, but when traits
are involved, it might be a different one.
2021-08-12 14:35:13 +02:00
Jeremy Mikola
858d0c0916 Include class name in Serializable deprecation message
The deprecation message was originally introduced in 3e6b447 (#6494).

I first encountered this notice when testing the MongoDB extension
with PHP 8.1, which produced many duplicate messages that provided
no detail about the particular class that needed to be fixed.

Closes GH-7346.
2021-08-11 10:35:47 +02:00
Nikita Popov
315f40942b
Always use CE_CACHE, remove TYPE_HAS_CE (#7336)
Currently, CE_CACHE on strings is only used with opcache interned strings. This
patch extends usage to non-opcache interned strings as well. This means that
most type strings can now make use of CE_CACHE even if opcache is not loaded,
which allows us to remove TYPE_HAS_CE kind, and fix some discrepancies
depending on whether a type stores a resolved or non-resolved name.

There are two cases where CE_CACHE will not be used:

 * When opcache is not used and a permanent interned string (that is not an
   internal class name) is used as a type name during the request. In this case
   we can't allocate a map_ptr index for the permanent string, as it would be
   not be in the permanent map_ptr index space.
 * When opcache is used but the script is not cached (e.g. eval'd code or
   opcache full). If opcache is used, we can't allocate additional map_ptr
   indexes at runtime, because they may conflict with indexes allocated by
   opcache.

In these two cases we would end up not using CE caching for property types
(argument/return types still have the separate cache slot).
2021-08-11 10:28:52 +02:00
Nikita Popov
6d5ae6496c Fix ASSIGN_DIM to NEXT with rc=1 reference value
The reference wrapper was destroyed while value still pointed into
it and was later used to assign the ASSIGN_DIM return value. This
could be fixed either by moving the return value assignment earlier,
or by working with the value that has been stored in the array.
I'm going with the latter here, because that matches what the
non-NEXT codepath does via assign_to_variable more closely.

Fixes oss-fuzz #36807.
2021-08-03 10:25:24 +02:00
Joe Watkins
05ef6334cd
Fix bug #81303 improve match errors 2021-08-02 17:31:26 +02:00
Javier Eguiluz
ffc8717401
Fix some typos (#7320) 2021-07-31 08:34:57 +02:00
Nikita Popov
1a370d3321 Skip some tests under --preload
A genuine problem here is that we sometime get different class
casing due interaction with the ZSTR CE cache. Ignore these for
now.
2021-07-30 17:26:39 +02:00
Nikita Popov
9e66455fbc Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix parameter name in count() error message
2021-07-29 14:25:22 +02:00
Nikita Popov
6c7b322de2 Fix parameter name in count() error message
This parameter has been renamed to $value.
2021-07-29 14:25:13 +02:00
Nikita Popov
fc45223f85 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix parameter name in call_user_func() error message
2021-07-29 12:49:17 +02:00
Nikita Popov
840e441d2d Fix parameter name in call_user_func() error message
This parameter name has been changed to $callback.
2021-07-29 12:48:25 +02:00
Nikita Popov
380e705fc2 Use consistent line numbers for early binding errors
Non-early-bound classes report inheritance errors at the first line
of the class, if no better line information is available (we should
really store line numbers for properties at least...) Early bound
classes report it at the last line of the class instead.

Make the error reporting consistent by always reporting at the
first line.
2021-07-28 12:35:20 +02:00
Máté Kocsis
663536d7d9
Improve class inheritance error messages (#7307) 2021-07-27 09:42:37 +02:00
Nikita Popov
a374230c15 Add support for internal enums
This adds support for internal enums with the same basic approach
as userland enums. Enum values are stored as CONSTANT_AST and
objects created during constant updating at runtime. This means
that we need to use mutable_data for internal enums.

This just adds basic support and APIs, it does not include the
stubs integration from #7212.

Closes GH-7302.
2021-07-27 09:19:14 +02:00
Máté Kocsis
3babe9576e
Validate that promoted readonly properties have a type 2021-07-25 13:13:19 +02:00
Nikita Popov
921e1052db Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix bug #66719
2021-07-23 11:25:17 +02:00
Nikita Popov
90ee1c36d7 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix bug #66719
2021-07-23 11:24:59 +02:00
Nikita Popov
dfd05da97f Fix bug #66719
While parent:: should inherit the called scope, it should only do
so if it is compatible. If there is no called scope, or it is not
a subtype of the scope, we should fall back to the scope.
2021-07-23 11:24:22 +02:00
Nikita Popov
a8926474cb Set called_scope in __callStatic closure trampoline 2021-07-23 10:58:05 +02:00
Máté Kocsis
fc56de113c
Add support for generating readonly properties via stubs (#7297) 2021-07-22 11:09:10 +02:00
Nikita Popov
578b785ecf Don't return reference from Fiber::getReturn()
Even if the fiber function returns by reference, we must return
a value from Fiber::getReturn() to satisfy the function signature.

Fixes oss-fuzz #36417.
2021-07-22 09:44:19 +02:00
Nikita Popov
11b990f848 Forbid multiple readonly modifiers
Same as for other modifiers.
2021-07-21 12:19:06 +02:00
Joe Watkins
27bb57356c
Merge branch 'master' of github.com:php/php-src
* 'master' of github.com:php/php-src:
  Implement readonly properties
2021-07-20 12:32:51 +02:00
Joe Watkins
570d9b63e9
Not serializable flag permeation 2021-07-20 12:28:35 +02:00
Nikita Popov
6780aaa532 Implement readonly properties
Add support for readonly properties, for which only a single
initializing assignment from the declaring scope is allowed.

RFC: https://wiki.php.net/rfc/readonly_properties_v2

Closes GH-7089.
2021-07-20 12:05:46 +02:00
Nikita Popov
814a932734 Add ZEND_ACC_NOT_SERIALIZABLE flag
This prevents serialization and unserialization of a class and its
children in a way that does not depend on the zend_class_serialize_deny
and zend_class_unserialize_deny handlers that will be going away
in PHP 9 together with the Serializable interface.

In stubs, `@not-serializable` can be used to set this flag.

This patch only uses the new flag for a handful of Zend classes,
converting the remainder is left for later.

Closes GH-7249.
Fixes bug #81111.
2021-07-19 15:59:11 +02:00
Kamil Tekiela
052af90b86 Deprecate autovivification on false
Deprecate automatically converting "false" into an empty array
on write operands. Autovivification continues to be supported
for "null" values, as well as undefined/uninitialized values.

RFC: https://wiki.php.net/rfc/autovivification_false

Closes GH-7131.

Co-authored-by: Tyson Andre <tysonandre775@hotmail.com>
Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-07-19 14:49:37 +02:00
Máté Kocsis
75a678a7e3
Declare tentative return types for Zend (#7251)
Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-07-19 13:44:20 +02:00
Nikita Popov
b6dcab2cbb Fix assert with attribute + first-class callable in assert
This is going to result in a compile-time error, but AST printing
is invoked first and should handle it gracefully. Handle it by
falling back to more generic printing code.

Fixes oss-fuzz #36264.
2021-07-19 12:08:03 +02:00
George Peter Banyard
9e1c961110 Fix intersection types being nullable via implicit forced nullability 2021-07-17 11:14:58 +02:00
George Peter Banyard
3cfcfacd36 Fix bug pointed out in feature request 81268
The error message which is generated when one tries to assign null to an intersection type property is wrong and misleading
2021-07-17 11:14:58 +02:00
Nikita Popov
1bc5bd7fe2 Handle both WARNING and UNRESOLVED during early binding
We would previously early exit on the WARNING, and miss the
later UNRESOLVED.
2021-07-15 15:27:15 +02:00
Nikita Popov
f556a30b92 Narrow ArrayIterator::key() return type
This can only return string|int|null, not any key type.
2021-07-15 11:03:50 +02:00
Nikita Popov
53aed48e5d Allow objects in define()
This was separately discussed in https://externals.io/message/114863,
but also necessary for consistency now that
https://wiki.php.net/rfc/new_in_initializers has landed.

Closes GH-7149.
2021-07-15 10:09:56 +02:00
Nikita Popov
59a5f89f11 Merge branch 'PHP-8.0'
* PHP-8.0:
  Undef slot before destroying in unset_property
2021-07-15 09:32:55 +02:00
Nikita Popov
567e53ea58 Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Undef slot before destroying in unset_property
2021-07-15 09:32:26 +02:00
Nikita Popov
ebd3a21002 Undef slot before destroying in unset_property
We need to make sure that destructors can't access the partially
destroyed property. Do the same we do in HTs.

Fixes oss-fuzz #36205.
2021-07-15 09:31:19 +02:00
Máté Kocsis
6d805ed275
Declare tentative return types for ext/spl - part 2
Closes GH-7235
2021-07-14 15:19:51 +02:00
Nikita Popov
90e6a74016 Merge branch 'PHP-8.0'
* PHP-8.0:
  Drop incorrect cache_slot optimization for typed properties
2021-07-14 15:10:58 +02:00
Nikita Popov
982c833acd Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Drop incorrect cache_slot optimization for typed properties
2021-07-14 15:10:11 +02:00
Nikita Popov
ba8bcf3992 Drop incorrect cache_slot optimization for typed properties
For a particular assignment, a non-coerced constant assignment
value will remain valid. However, opcache merges cache slots for
all identical property references, which means that this
optimization also disables property type checks for all other
operands on the property that occur in the same functions.

This could be addressed by blocking cache slot merging in opcache,
but I prefer dropping it entirely instead. It does not seem
important enough to warrant doing that.
2021-07-14 15:08:33 +02:00
Joe Watkins
d0b09a7be4 Add first-class callables
Support acquiring a Closure to a callable using the syntax
func(...), $obj->method(...), etc. This is essentially a
shortcut for Closure::fromCallable().

RFC: https://wiki.php.net/rfc/first_class_callable_syntax

Closes GH-7019.

Co-Authored-By: Nikita Popov <nikita.ppv@gmail.com>
2021-07-14 14:37:25 +02:00
Joe Watkins
6a9daafed4
Fix bug #81237 comparison of fake closures doesn't work 2021-07-13 15:35:55 +02:00
Nikita Popov
52d3d0d8d7 Add limited support for new in initializers
Add support for new expressions inside parameter default values,
static variable initializers, global constant initializers and
attribute arguments.

RFC: https://wiki.php.net/rfc/new_in_initializers

Closes GH-7153.
2021-07-13 14:03:20 +02:00
Máté Kocsis
c6357b804e
Declare tentative return types for ext/spl - part 1 (#7115) 2021-07-13 13:04:45 +02:00
Nikita Popov
5f8ed7765a Fix GC of object properties HT
We partially fixed this in bug #78379, but still don't handle
the case where the properties array is marked as grey first,
which causes a delref to not be performed later.

Fix this by treating the object properties HT the same way as
other refcounted values, including addrefs/delrefs. The object
dtor code already handles properties HT with NULL GC type, so
out of order destruction should not be a problem.

Fixes oss-fuzz #36023.
2021-07-12 11:30:20 +02:00
Nikita Popov
a80360dbed Deprecate direct access to static trait members
Static trait members may only be accessed through a class in which
the trait is used, not directly on the trait.

A complication here is that we should not store static
methods/properties for which a deprecation is triggered in a
cache slot. As the check for this is simple and cheap, I'm handling
this in the cache slot population code in the VM. The alternative
would be to pass the cache slot down into the fetching code.

Part of https://wiki.php.net/rfc/deprecations_php_8_1.
2021-07-09 14:12:28 +02:00
Nikita Popov
f0b190c32d Deprecate return by ref from void function
Part of https://wiki.php.net/rfc/deprecations_php_8_1.
2021-07-08 16:47:37 +02:00
Nikita Popov
dcc8463ae5 Deprecate IAP functions on objects
Deprecate use of key(), current(), next(), prev(), reset() and
end() on objects. Cast the object to array first.

Part of https://wiki.php.net/rfc/deprecations_php_8_1.
2021-07-08 15:28:33 +02:00
Marco Pivetta
6e16e1daa9 Make ReflectionProperty/Method always accessible
With this patch, it is no longer required to call
`ReflectionProperty#setAccessible()` or
`ReflectionMethod#setAccessible()` with `true`.

If a userland consumer already got to the point of accessing
object/class information via reflection, it makes little sense
for `ext/reflection` to disallow accessing `private`/`protected`
symbols by default.

After this patch, calling `ReflectionProperty#setAccessible(true)`
or `ReflectionMethod#setAccessible(true)` on newly instantiated
`ReflectionProperty` or `ReflectionMethod` respectively will have
no effect.

RFC: https://wiki.php.net/rfc/make-reflection-setaccessible-no-op

Closes GH-5412.
2021-07-08 10:55:38 +02:00
Nikita Popov
2763f14dee Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix constant update for shadowed private property
2021-07-08 10:14:21 +02:00
Nikita Popov
58699ffcf1 Fix constant update for shadowed private property
Updating based on the properties info HT will miss private parent
properties that have been shadowed in the child class. Instead,
perform updating directly on the default properties table.

We can't do the same for static properties, because those don't
have a convenient way to look up the property type from the
property offset. However, I don't believe the problem exists for
static properties, because we're always going to be using the
property on the class it was declared on, while children only hold
INDIRECT references. As such, this should be covered by parent
class const updating.

Fixes oss-fuzz #35906.
2021-07-08 10:12:40 +02:00
Nikita Popov
ce3846cd87 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix use after free on compound division by zero
2021-07-07 09:38:57 +02:00
Nikita Popov
62ecf54f35 Fix use after free on compound division by zero
We can't destroy the result operand early, because the division
might fail, in which case we need to preserve the original value.
Place the division result in a temporary zval, and only copy it
on success.

Fixes oss-fuzz #35876.
2021-07-07 09:38:30 +02:00
Máté Kocsis
a5360e80c2
Add support for final class constants
RFC: https://wiki.php.net/rfc/final_class_const

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2021-07-06 21:42:38 +02:00
George Peter Banyard
069a9fa5e4
Pure Intersection types (#6799)
Implement pure intersection types RFC

RFC: https://wiki.php.net/rfc/pure-intersection-types

Co-authored-by: Nikita Popov <nikic@php.net>
Co-authored-by: Ilija Tovilo <ilutov@php.net>
2021-07-05 14:11:03 +02:00
Nikita Popov
629965c80f Handle promoted exception in int|string type
Fixes oss-fuzz #35790.
2021-07-05 10:48:20 +02:00
Nikita Popov
29b82695b5 Fix leak of callable error if exception also thrown 2021-07-02 16:33:14 +02:00
Nikita Popov
52cf7ab8a2 Fix bug #80072: Root live tmpvars after GC
TMPVAR operands are destroyed using zval_ptr_dtor_nogc(), because
they usually cannot contain cycles. However, there are some rare
exceptions where this is possible, e.g. unserialize() return value.
In such cases we rely on the producing code to root the value. If
a GC run occurs between the rooting and consumption of the value,
we would end up leaking it. To avoid this, root all live TMPVAR
values after a GC run.

Closes GH-7210.
2021-07-02 15:28:36 +02:00
Nikita Popov
3321440166 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix return value of wrong fucntion by-ref assign
2021-07-02 11:18:46 +02:00
Nikita Popov
6617829f1b Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix return value of wrong fucntion by-ref assign
2021-07-02 11:18:09 +02:00
Nikita Popov
96bf925cde Fix return value of wrong fucntion by-ref assign
We should be using the result of zend_assign_to_variable() here,
which will deref prior to potential freeing.

Fixes oss-fuzz #29899.
2021-07-02 11:15:31 +02:00
Nikita Popov
53fba3a13d Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #80173
2021-07-02 10:08:57 +02:00
Nikita Popov
4e66e6a73a Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fixed bug #80173
2021-07-02 10:08:40 +02:00
Nikita Popov
bdc60fa7da Fixed bug #80173
The analysis in the bug report wasn't correct (at least not in
this case -- there may still be a more general problem here),
the issue was that write_property returned the original variable_ptr
rather than the zend_assign_to_variable() return value, which will
DEREF the variable before overwriting it.
2021-07-02 10:07:40 +02:00
Nikita Popov
353f963bba Init STRLEN result when deprecation promoted to exception
Move the result initialization before HANDLE_EXCEPTION(), the
actual value doesn't matter.

This fixes one of the issues report in bug #81190.
2021-07-01 16:22:27 +02:00
Nikita Popov
36cb48c937 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix leak on foreach by ref assign to property
2021-07-01 15:49:57 +02:00
Nikita Popov
2efee442eb Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fix leak on foreach by ref assign to property
2021-07-01 15:49:34 +02:00
Nikita Popov
36f5d719f5 Fix leak on foreach by ref assign to property
In this case we ended up creating an ASSIGN_OBJ_REF with VAR
result operand, which was not freed.

Fix this by implementing assign_ref_znode the same was as
assign_znode, i.e. performing an assignment with result and
then freeing the result, which will result mark the result as
UNUSED. This is more robust than the special handling for
result == NULL that was used before.

This fixes one of the issues reported in bug #81190.
2021-07-01 15:48:39 +02:00
Nikita Popov
d3deb8253d Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix leak on div by zero compound assignment with coercion
2021-07-01 14:50:45 +02:00
Nikita Popov
540fed1b36 Fix leak on div by zero compound assignment with coercion
The result == op1 check did not work properly here, because op1
was &op1_copy at this point. Move the division by zero reporting
out of the _base function, so it can check the original op1.
2021-07-01 14:50:18 +02:00
Nikita Popov
65bbd92dca Initialize retval on bitwise_not exception 2021-07-01 13:21:41 +02:00
Patrick Allaert
ac18dd0dc7 Prefer EXPECT over EXPECTF 2021-06-29 17:13:02 +02:00
Máté Kocsis
773e9ba5d6
Mention ReturnTypeWillChange attribute in the error message (#7183) 2021-06-28 14:56:21 +02:00
Martin Schröder
7713302fbd Implemented Fiber GC handler 2021-06-28 13:08:48 +02:00
Tyson Andre
e00b3ec6ae
Fix false positive recursion warning for var_export of enums (#7201) 2021-06-26 15:33:39 -04:00
George Peter Banyard
c66fd72dbb
Fix deprecated float to int tests
Missed those as they are not present on the 8.0 branch
2021-06-18 19:14:22 +01:00
George Peter Banyard
4939d2cec1
Merge branch 'PHP-8.0'
* PHP-8.0:
  Fix test
  Fix bug #81159: Object to int warning when using an object as a string offset
  Fix bug #81163 indirect vars in __sleep
2021-06-18 18:11:46 +01:00
George Peter Banyard
f0fd5922ee
Fix bug #81159: Object to int warning when using an object as a string offset
Closes GH-7167
2021-06-18 18:07:22 +01:00
Aaron Piotrowski
865fb353f5
Rename Fiber::this() to Fiber::getCurrent() (#7155) 2021-06-18 11:02:02 -05:00
George Peter Banyard
acb78035b6
Add proper EXTENSIONS section for tests in Zend/ 2021-06-18 01:05:05 +01:00
Nikita Popov
b64213872a Fix missing error for single index unset on wrong type
The error was correctly thrown for a nested index, but not for a
single index. Make sure both have the same behavior.
2021-06-15 14:41:11 +02:00
Aaron Piotrowski
fdc22744a8
Add API to prevent Fiber switch in select contexts
Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
2021-06-14 14:19:00 -05:00
Nikita Popov
1c08f8a48a Allow named args after unpack
Currently, argument unpacking and named arguments cannot be mixed
at all. This relaxes the restriction to allow
foo(...$args, named: $arg). The variant foo(named: $arg, ...$args)
is still forbidden, because we can't ensure that positional
parameters come before named parameters in that case (without more
intrusive changes). Effectively this just enforces a required style,
as the order of unpack and named args doesn't matter for the cases
where both could be well-defined.

ML discussion: https://externals.io/message/114589

Closes GH-7009.
2021-06-14 10:32:36 +02:00
Nikita Popov
71fb83567f Fix bug #80945: Don't throw undefined array key warning in ArrayObject unset()
This makes the behavior of ArrayObject the same as far plain
arrays, which don't throw a warning when unsetting a key that
already doesn't exit.
2021-06-14 10:14:38 +02:00
Nikita Popov
39131219e8
Migrate more SKIPIF -> EXTENSIONS (#7139)
This is a mix of more automated and manual migration. It should remove all applicable extension_loaded() checks outside of skipif.inc files.
2021-06-11 12:58:44 +02:00
Nikita Popov
7485978339
Migrate SKIPIF -> EXTENSIONS (#7138)
This is an automated migration of most SKIPIF extension_loaded checks.
2021-06-11 11:57:42 +02:00
Nikita Popov
b58d74547f Rerun GC if destructors encountered
Since PHP 7.4 objects that have a destructor require two GC runs
to be collected. Currently the collection is delayed to the next
automatic GC run. However, in some cases this may result in a large
increase in memory usage, as in one of the cases of bug #79519.

See also bug #78933 and bug #81117 where the current behavior is
unexpected for users.

This patch will automatically rerun GC if destructors were encountered.
I think this should not have much cost, because it is very likely that
objects on which the destructor has been called really are garbage,
so the extra GC run should not be doing wasted work.

Closes GH-5581.
2021-06-09 14:53:14 +02:00
Aaron Piotrowski
2184422adc
Merge fiber switching functions (#7106)
Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
2021-06-08 08:23:56 -05:00
Nikita Popov
291d8db7c5 Merge branch 'PHP-8.0'
* PHP-8.0:
  Fixed bug #81104
2021-06-08 14:34:08 +02:00
Nikita Popov
d29f15ce5f Merge branch 'PHP-7.4' into PHP-8.0
* PHP-7.4:
  Fixed bug #81104
2021-06-08 14:33:29 +02:00
Nikita Popov
d8165c2502 Fixed bug #81104
When the memory limit is restored during shutdown, we may still
be using a lot of memory. Ignore the failure at that point and
set it again after the MM is shut down, at which point memory
usage should be at its lowest point.
2021-06-08 14:31:55 +02:00