summaryrefslogtreecommitdiff
path: root/Zend/zend_inheritance.c
Commit message (Collapse)AuthorAgeFilesLines
* Remove unnecessary property unmangling in trait bindingNikita Popov2021-03-261-18/+2
| | | | | The unmangled name is already available as the hashtable key, use it directly.
* Fix handling of unknown class in trait precedence listNikita Popov2021-03-191-1/+1
| | | | Fixes oss-fuzz #31983.
* Implement enumsIlija Tovilo2021-03-171-0/+16
| | | | | | | | RFC: https://wiki.php.net/rfc/enumerations Co-authored-by: Nikita Popov <nikita.ppv@gmail.com> Closes GH-6489.
* Fixed compilation warningDmitry Stogov2021-03-121-0/+1
|
* Inheritance cache optimizationDmitry Stogov2021-03-111-28/+34
|
* Fix static variable behavior with inheritanceNikita Popov2021-02-181-24/+15
| | | | | | | | | | | | When a method is inherited, the static variables will now always use the initial values, rather than the values at the time of inheritance. As such, behavior no longer depends on whether inheritance happens before or after a method has been called. This is implemented by always keeping static_variables as the original values, and static_variables_ptr as the modified copy. Closes GH-6705.
* Link unbound simple classes (without parent/intefaces/traits) in first place.Dmitry Stogov2021-02-101-0/+2
|
* Use zend_type.ce_cache__ptr for caching class resulution during ↵Dmitry Stogov2021-02-101-2/+6
| | | | argument/result type checks
* Added Inheritance Cache.Dmitry Stogov2021-02-091-48/+426
| | | | | | | | | | This is a new transparent technology that eliminates overhead of PHP class inheritance. PHP classes are compiled and cached (by opcahce) separately, however their "linking" was done at run-time - on each request. The process of "linking" may involve a number of compatibility checks and borrowing methods/properties/constants form parent and traits. This takes significant time, but the result is the same on each request. Inheritance Cache performs "linking" for unique set of all the depending classes (parent, interfaces, traits, property types, method types involved into compatibility checks) once and stores result in opcache shared memory. As a part of the this patch, I removed limitations for immutable classes (unresolved constants, typed properties and covariant type checks). So now all classes stored in opcache are "immutable". They may be lazily loaded into process memory, if necessary, but this usually occurs just once (on first linking). The patch shows 8% improvement on Symphony "Hello World" app.
* Mark classes cached by opcache by ZEND_ACC_CACHED flag and prevent useless ↵Dmitry Stogov2021-01-191-4/+6
| | | | copying and desrpoying of immutable data.
* Avoid modification of trait infoDmitry Stogov2021-01-191-3/+0
|
* Replace zend_bool uses with boolNikita Popov2021-01-151-19/+19
| | | | | | | 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.
* 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