summaryrefslogtreecommitdiff
path: root/Zend/zend_inheritance.c
Commit message (Collapse)AuthorAgeFilesLines
* Fix infinite recursion in unlinked_instanceofNikita Popov2021-01-051-1/+2
| | | | | | | 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.
* Fixed bug #80391Nikita Popov2020-11-241-0/+4
| | | | | Iterable was not considered a subtype of array|object, and thus also not a subtype of mixed.
* Fix static variable in methods inheritance during preloadingNikita Popov2020-11-041-7/+9
| | | | | This is now "bug compatible" with the normal behavior, and more imporantly, does not crash :)
* Fix use of type copy ctor when importing trait propertiesNikita Popov2020-11-031-2/+3
| | | | | We shouldn't call the copy constructor inside the original type, duh.
* Allow unlinked classes when performing in_compilation variance checkNikita Popov2020-11-031-4/+2
| | | | | As preloading runs in in_compilation mode, we also need to allow use of unlinked classes in lookup_class().
* Fix variance checks on resolved union typesNikita Popov2020-11-031-53/+57
| | | | | | 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.
* Fix bug #80055Nikita Popov2020-10-151-39/+56
| | | | | | | 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.
* Merge branch 'PHP-7.4'Nikita Popov2020-10-061-12/+10
|\ | | | | | | | | * PHP-7.4: Fix bug #80126
| * Fix bug #80126Nikita Popov2020-10-061-12/+10
| | | | | | | | | | | | When performing an unlinked instanceof, we also need to consider interfaces of parent classes, as they may not have been inherited yet.
* | Improve type declarations for Zend APIsGeorge Peter Banyard2020-08-281-2/+2
| | | | | | | | | | | | | | | | | | 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
* | Add common code for magic method assignmentNikita Popov2020-07-201-39/+1
| | | | | | | | This was repeated three times.
* | Ignore inheritance rules on private methodsPedro Magalhães2020-07-151-4/+8
| | | | | | | | Closes GH-5401
* | Cache __unserialize() instead of unserialize()Nikita Popov2020-06-261-10/+10
| | | | | | | | | | We should use these cache slots for the new object serialization mechanism rather than the old one.
* | Add ZVAL_OBJ_COPY macroNikita Popov2020-06-171-2/+1
| | | | | | | | | | For the common ZVAL_OBJ + GC_ADDREF pattern. This mirrors the existing ZVAL_STR_COPY API.
* | Use ZEND_UNREACHABLE() instead of ZEND_ASSERT(0)Christoph M. Becker2020-06-161-1/+1
| | | | | | | | | | | | | | | | | | 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>
* | Add AttributesBenjamin Eberlei2020-06-041-1/+12
| | | | | | | | Co-authored-by: Martin Schröder <m.schroeder2007@gmail.com>
* | Add support for the mixed typeMáté Kocsis2020-05-221-2/+2
| | | | | | | | | | | | | | RFC: https://wiki.php.net/rfc/mixed_type_v2 Closes GH-5313 Co-authored-by: Dan Ackroyd <danack@basereality.com>
* | Merge branch 'PHP-7.4'Nikita Popov2020-05-041-1/+8
|\ \ | |/ | | | | | | * PHP-7.4: Fixed bug #79548
| * Fixed bug #79548Nikita Popov2020-05-041-1/+8
| | | | | | | | | | When duplicating user functions with static variables, make sure that we init a new map ptr slot for the static variables.
* | Fix treatment of "self" when validating against trait methodNikita Popov2020-04-231-35/+62
| | | | | | | | | | | | | | 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.
* | Improve the default value format in incompatible signature error messagesMáté Kocsis2020-04-101-2/+6
| | | | | | | | Closes GH-5361
* | Store default parameter values of internal functions in arg infoMáté Kocsis2020-04-081-3/+8
| | | | | | | | | | | | | | 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>
* | Assert that arginfo parameter name is presentNikita Popov2020-04-071-9/+3
| |
* | Check abstract method signatures coming from traitsNikita Popov2020-03-261-72/+58
| | | | | | | | | | | | RFC: https://wiki.php.net/rfc/abstract_trait_method_validation Closes GH-5068.
* | Enable better trait conflict error messageNikita Popov2020-03-101-5/+0
| | | | | | | | | | | | 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.
* | Require non-absolute trait method refs to be unambiguousNikita Popov2020-03-101-2/+6
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Implement interfaces after all methods availableNikita Popov2020-03-041-18/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Small code cleanupNikita Popov2020-03-031-4/+3
| | | | | | | | | | | | | | 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.
* | Resolve trait alias refers to earlierNikita Popov2020-03-031-84/+48
| | | | | | | | | | | | 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.
* | Store aliased name of trait methodNikita Popov2020-03-031-5/+11
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Avoid duplicate calls to interface implementation handlerNikita Popov2020-02-281-1/+3
| |
* | Require all internal functions to have arginfoNikita Popov2020-02-261-8/+0
| |
* | Add static return typeNikita Popov2020-02-171-3/+34
| | | | | | | | | | | | | | | | | | | | 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.
* | Remove ZEND_ACC_IMPLEMENT_INTERFACES flagNikita Popov2020-02-061-2/+2
| | | | | | | | | | | | | | 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".
* | Remove ZEND_ACC_IMPLEMENTS_TRAITS flagNikita Popov2020-02-061-1/+1
| | | | | | | | This is equivalent to checking ce->num_traits.
* | Merge branch 'PHP-7.4'Nikita Popov2020-01-301-2/+11
|\ \ | |/ | | | | | | * PHP-7.4: Fix copying of functions in variance obligations
| * Fix copying of functions in variance obligationsNikita Popov2020-01-301-2/+11
| | | | | | | | Only copy sizeof(zend_internal_function) for internal functions.
* | Merge branch 'PHP-7.4'Nikita Popov2020-01-281-8/+10
|\ \ | |/ | | | | | | * PHP-7.4: Fixed bug #78989
| * Fixed bug #78989Nikita Popov2020-01-281-8/+10
| | | | | | | | | | | | | | | | 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.
* | Allow variadic arguments to replace non-variadic onesNikita Popov2020-01-231-27/+28
| | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Prefer using declaring class rather than direct parent in errorNikita Popov2020-01-211-4/+4
| | | | | | | | | | Point to the class that actually declares the property, which is not necessarily the same as the direct parent class.
* | Fix #78880 Another roundMáté Kocsis2020-01-191-1/+1
| |
* | Use zend_type inside type listsNikita Popov2020-01-171-47/+27
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | 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.
* | Merge branch 'PHP-7.4'Nikita Popov2019-12-181-8/+6
|\ \ | |/ | | | | | | * PHP-7.4: Fixed bug #78776
| * Fixed bug #78776Nikita Popov2019-12-181-9/+6
| | | | | | | | | | By using the normal inheritance check if the parent is abstract as well.
* | Merge branch 'PHP-7.4'Nikita Popov2019-12-091-1/+1
|\ \ | |/ | | | | | | * PHP-7.4: Use unmangled named in property type inheritance error
| * Use unmangled named in property type inheritance errorNikita Popov2019-12-091-1/+1
| |
* | Fix incorrect assertion in property type variance checkNikita Popov2019-12-041-1/+1
| | | | | | | | | | | | | | Only one of the status has to be UNRESOLVED, the other could also be SUCCESS. Fixes oss-fuzz #19108 and oss-fuzz #19111.
* | Implement union typesNikita Popov2019-11-081-118/+202
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | According to RFC: https://wiki.php.net/rfc/union_types_v2 The type representation now makes use of both the pointer payload and the type mask at the same time. Additionall, zend_type_list is introduced as a new kind of pointer payload, which is used to store multiple class types. Each of the class types is a tagged pointer, which may be either a class name or class entry. The latter is only used for typed properties, while arguments/returns will instead use cache slots. A type list can contain a mix of both names and CEs at the same time, as not all classes may be resolvable. One thing this is missing is support for union types in arginfo and stubs, which I want to handle separately. I've also dropped the special object code from the JIT implementation for now -- I plan to add this back in a different form at a later time. For now I did not want to include non-trivial JIT changes together with large functional changes. Another possible piece of follow-up work is to implement "iterable" as an internal alias for "array|Traversable". I believe this will eliminate quite a few special-cases that had to be implemented. Closes GH-4838.
* | Make zend_type a 2-field structNikita Popov2019-11-081-11/+12
| | | | | | | | | | | | | | | | | | | | | | | | | | We now store the pointer payload and the type mask separately. This is in preparation for union types, where we will be using both at the same time. To avoid increasing the size of arginfo structures, the pass_by_reference and is_variadic fields are now stored as part of the type_mask (8-bit are reserved for custom use). Different types of pointer payloads are distinguished based on bits in the type_mask.