Commit Graph

321 Commits

Author SHA1 Message Date
Dmitry Stogov
b3bbb8fe3b Mark classes cached by opcache by ZEND_ACC_CACHED flag and prevent useless copying and desrpoying of immutable data. 2021-01-19 11:55:09 +03:00
Dmitry Stogov
c195fcd678 Avoid modification of trait info 2021-01-19 11:54:01 +03:00
Nikita Popov
3e01f5afb1 Replace zend_bool uses with bool
We're starting to see a mix between uses of zend_bool and bool.
Replace all usages with the standard bool type everywhere.

Of course, zend_bool is retained as an alias.
2021-01-15 12:33:06 +01:00
Nikita Popov
dd335359e9 Fix infinite recursion in unlinked_instanceof
I suspect this is only a partial fix for the issue, it's probably
possible to recurse through a more complex pathway as well.

Fixes oss-fuzz #28961.
2021-01-05 13:03:41 +01:00
Nikita Popov
912cb8b8b5 Fixed bug #80391
Iterable was not considered a subtype of array|object, and thus
also not a subtype of mixed.
2020-11-24 10:09:28 +01:00
Nikita Popov
670fe594b9 Fix static variable in methods inheritance during preloading
This is now "bug compatible" with the normal behavior, and more
imporantly, does not crash :)
2020-11-04 15:42:52 +01:00
Nikita Popov
9fd8e00f1a Fix use of type copy ctor when importing trait properties
We shouldn't call the copy constructor inside the original type,
duh.
2020-11-03 15:29:18 +01:00
Nikita Popov
7e55317558 Allow unlinked classes when performing in_compilation variance check
As preloading runs in in_compilation mode, we also need to allow
use of unlinked classes in lookup_class().
2020-11-03 14:49:10 +01:00
Nikita Popov
ee934f8245 Fix variance checks on resolved union types
This is a bit annoying: When preloading is used, types might be
resolved during inheritance checks, so we need to deal with CE
types rather than just NAME types everywhere.
2020-11-03 14:19:15 +01:00
Nikita Popov
4ece62fba9 Fix bug #80055
We need to perform trait scope fixup for both methods involved
in the inheritance check. For that purpose we already need to
thread through a separate fn scope through the entire inheritance
checking machinery.
2020-10-15 14:24:25 +02:00
Nikita Popov
ec484a0788 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix bug #80126
2020-10-06 16:34:02 +02:00
Nikita Popov
3b7c8bb973 Fix bug #80126
When performing an unlinked instanceof, we also need to consider
interfaces of parent classes, as they may not have been inherited
yet.
2020-10-06 16:33:14 +02:00
George Peter Banyard
fa8d9b1183 Improve type declarations for Zend APIs
Voidification of Zend API which always succeeded
Use bool argument types instead of int for boolean arguments
Use bool return type for functions which return true/false (1/0)
Use zend_result return type for functions which return SUCCESS/FAILURE as they don't follow normal boolean semantics

Closes GH-6002
2020-08-28 15:41:27 +02:00
Nikita Popov
7fd4212cc0 Add common code for magic method assignment
This was repeated three times.
2020-07-20 14:57:10 +02:00
Pedro Magalhães
272b887b7b Ignore inheritance rules on private methods
Closes GH-5401
2020-07-15 17:09:57 +01:00
Nikita Popov
1314ccbf8c Cache __unserialize() instead of unserialize()
We should use these cache slots for the new object serialization
mechanism rather than the old one.
2020-06-26 10:54:40 +02:00
Nikita Popov
15846ff115 Add ZVAL_OBJ_COPY macro
For the common ZVAL_OBJ + GC_ADDREF pattern.
This mirrors the existing ZVAL_STR_COPY API.
2020-06-17 16:36:56 +02:00
Christoph M. Becker
92c4b06513 Use ZEND_UNREACHABLE() instead of ZEND_ASSERT(0)
Instead of marking unreachable code with `ZEND_ASSERT(0)`, we introduce
`ZEND_UNREACHABLE()`, so that MSVC which does not consider `assert(0)`
to mark unreachable code does no longer trigger C4715[1] warnings in
debug builds.  This may be useful for other compilers as well.

[1] <https://docs.microsoft.com/de-de/cpp/error-messages/compiler-warnings/compiler-warning-level-1-c4715?view=vs-2019>
2020-06-16 18:39:09 +02:00
Benjamin Eberlei
a7908c2d11 Add Attributes
Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
2020-06-04 18:19:49 +02:00
Máté Kocsis
aec4c0fd03
Add support for the mixed type
RFC: https://wiki.php.net/rfc/mixed_type_v2
Closes GH-5313

Co-authored-by: Dan Ackroyd <danack@basereality.com>
2020-05-22 16:08:12 +02:00
Nikita Popov
4c24545aab Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79548
2020-05-04 16:30:34 +02:00
Nikita Popov
21a9ad910b Fixed bug #79548
When duplicating user functions with static variables, make sure
that we init a new map ptr slot for the static variables.
2020-05-04 16:27:45 +02:00
Nikita Popov
cf7c68283d Fix treatment of "self" when validating against trait method
If we're validating a class method against a trait method, we need
to treat "self" in the trait method as the class where the method
is used. To achieve this, we need to thread the proto scope through
all methods, so it can be provided separately from proto.common->scope.
2020-04-23 11:41:34 +02:00
Máté Kocsis
fe9860c2b0
Improve the default value format in incompatible signature error messages
Closes GH-5361
2020-04-10 22:50:33 +02:00
Máté Kocsis
3709e74b5e
Store default parameter values of internal functions in arg info
Closes GH-5353. From now on, PHP will have reflection information
about default values of parameters of internal functions.

Co-authored-by: Nikita Popov <nikita.ppv@gmail.com>
2020-04-08 18:37:51 +02:00
Nikita Popov
c81cf1c7af Assert that arginfo parameter name is present 2020-04-07 16:05:33 +02:00
Nikita Popov
f74e30c07c Check abstract method signatures coming from traits
RFC: https://wiki.php.net/rfc/abstract_trait_method_validation

Closes GH-5068.
2020-03-26 10:07:22 +01:00
Nikita Popov
d9219f997d Enable better trait conflict error message
I don't think there is any reason to disable this anymore,
at least all the messages generated in tests look correct and
more useful.
2020-03-10 16:19:11 +01:00
Nikita Popov
fff5771ccc Require non-absolute trait method refs to be unambiguous
Currently, when writing something like

class X {
    use T1, T2 {
       func as otherFunc;
    }
    function func() {}
}

where both T1::func() and T2::func() exist, we will simply assume
that func refers to T1::func(). This is surprising, and it doesn't
really make sense that this particular method gets picked.

This commit validates that non-absolute method references are
unambiguous, i.e. refer to exactly one method. If there is
ambiguity, it is required to write T1::func as otherFunc or
similar.

Closes GH-5232.
2020-03-10 16:01:13 +01:00
Nikita Popov
c05a9c3dcd Implement interfaces after all methods available
The place where interface implementation handlers is called is
currently ill-defined: If the class implements interfaces itself,
the handlers for both the parent interfaces and the new interfaces
will be called after all methods are registered (post trait use).
If the class does not implement interfaces, then the parent
interface handlers are called early during inheritance (before
methods are inherited).

This commit moves the calls to always occur after all methods are
available. For userland classes this will be post trait import,
at the time where interfaces get implemented (whether the class
itself defines additional interfaces or not). For internal classes
it will be at the end of inheritance, as internal class declarations
do not have proper finalization.

This allows us to simplify the logic for implementing the magic
Iterator / IteratorAggregate interfaces. In particularly we can
now also automatically detect whether an extension of
IteratorAggregate can safely reuse a custom get_iterator handler,
or whether it needs to switch to the userland mechanism. The
Iterator case continues to rely on ZEND_ACC_REUSE_GET_ITERATOR
for this purpose, as a wholesale replacement is not possible there.
2020-03-04 10:29:21 +01:00
Nikita Popov
262f52d5e2 Small code cleanup
I found what the modifier code does with XOR pretty confusing.
It's just removing the PPP bits...

Also remove an outdated reference to OVERLOADED_FUNCTION.
2020-03-03 15:00:51 +01:00
Nikita Popov
2c5fcd57c0 Resolve trait alias refers to earlier
Make sure all trait method references are converted to absolute
method references in advance. This regresses one error message
that I don't think is particularly valuable.
2020-03-03 14:23:31 +01:00
Nikita Popov
53efa1b0c6 Store aliased name of trait method
Currently, trait methods are aliased will continue to use the
original function name. In a few places in the codebase, we will
try to look up the actual method name instead. However, this does
not work if an aliased method is used indirectly
(https://bugs.php.net/bug.php?id=69180).

I think it would be better to instead actually change the method
name to the alias. This is in principle easy: We have to allow
function_name to be changed even if op array is otherwise shared
(similar to static_variables). This means we need to addref/release
the function_name separately, but I don't think there is a
performance concern here (especially as everything is usually
interned).

There is a bit of complication in opcache, where we need to make
sure that the function name is released the correct number of times
(interning may overwrite the name in the original op_array, but we
need to release it as many times as the op_array is shared).

Fixes bug #69180.
Fixes bug #74939.
Closes GH-5226.
2020-03-03 11:55:48 +01:00
Nikita Popov
06ac14f7f2 Avoid duplicate calls to interface implementation handler 2020-02-28 12:17:01 +01:00
Nikita Popov
b35b0142e6 Require all internal functions to have arginfo 2020-02-26 10:05:20 +01:00
Nikita Popov
43443857b7 Add static return type
RFC: https://wiki.php.net/rfc/static_return_type

The "static" type is represented as MAY_BE_STATIC, rather than
a class type like "self" and "parent", as it has special
resolution semantics, and cannot be cached in the runtime cache.

Closes GH-5062.
2020-02-17 11:51:09 +01:00
Nikita Popov
53e527ad43 Remove ZEND_ACC_IMPLEMENT_INTERFACES flag
This is equivalent to checking ce->num_interfaces. The only subtle
moment is during inheritance, where num_interface may change when
parent interfaces are inherited. The check in zend_do_link_class
thus uses "interfaces", not "ce->num_interfaces".
2020-02-06 10:53:12 +01:00
Nikita Popov
f57f0920fd Remove ZEND_ACC_IMPLEMENTS_TRAITS flag
This is equivalent to checking ce->num_traits.
2020-02-06 10:45:49 +01:00
Nikita Popov
d5dd46fb09 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix copying of functions in variance obligations
2020-01-30 11:56:36 +01:00
Nikita Popov
68596ed71e Fix copying of functions in variance obligations
Only copy sizeof(zend_internal_function) for internal functions.
2020-01-30 11:55:38 +01:00
Nikita Popov
3bae1793ab Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78989
2020-01-28 10:44:37 +01:00
Nikita Popov
1146bdb9b2 Fixed bug #78989
Always operate on copies of the functions, so we don't reference
temporary trait methods that have gone out of scope.

This could be more efficient, but doing an allocated copy only when
strictly necessary turned out to be somewhat tricky.
2020-01-28 10:43:15 +01:00
Nikita Popov
e72bf63691 Allow variadic arguments to replace non-variadic ones
Any number of arguments can be replaced by a variadic one, so
long as the variadic argument is compatible (in the sense of
contravariance) with the subsumed arguments.

In particular this means that function(...$args) becomes a
near-universal signature: It is compatible with any function
signature that does not accept parameters by-reference.

This also fixes bug #70839, which describes a special case.

Closes GH-5059.
2020-01-23 15:23:31 +01:00
Nikita Popov
a3e29ba34a Prefer using declaring class rather than direct parent in error
Point to the class that actually declares the property, which is
not necessarily the same as the direct parent class.
2020-01-21 17:19:07 +01:00
Máté Kocsis
99db00b1f2
Fix #78880 Another round 2020-01-19 18:28:43 +01:00
Nikita Popov
bd1977282c Use zend_type inside type lists
Instead of having a completely independent encoding for type list
entries. This is going to use more memory, but I'm not particularly
concerned about that, as type unions that contain multiple classes
should be uncommon. On the other hand, this allows us to treat
top-level types and types inside lists mostly the same.

A new ZEND_TYPE_FOREACH macros allows to transparently treat list
and non-list types the same way. I'm not using it everywhere it could be
used for now, just the places that seemed most obvious.

Of course, this will make any future type system changes much simpler,
as it will not be necessary to duplicate all logic two times.
2020-01-17 09:37:54 +01:00
Nikita Popov
655d5c8383 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78776
2019-12-18 15:56:10 +01:00
Nikita Popov
4a61d842e7 Fixed bug #78776
By using the normal inheritance check if the parent is abstract
as well.
2019-12-18 15:55:45 +01:00
Nikita Popov
33e39f088a Merge branch 'PHP-7.4'
* PHP-7.4:
  Use unmangled named in property type inheritance error
2019-12-09 08:49:42 +01:00
Nikita Popov
5fcc12f505 Use unmangled named in property type inheritance error 2019-12-09 08:48:33 +01:00