Commit Graph

234 Commits

Author SHA1 Message Date
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
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
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
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
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
5fcc12f505 Use unmangled named in property type inheritance error 2019-12-09 08:48:33 +01:00
Nikita Popov
f1848a4b3f Fix bug #78226: Don't call __set() on uninitialized typed properties
Assigning to an uninitialized typed property will no longer trigger
a call to __set(). However, calls to __set() are still triggered if
the property is explicitly unset().

This gives us both the behavior people generally expect, and still
allows ORMs to do lazy initialization by unsetting properties.

For PHP 8, we should fine a way to forbid unsetting of declared
properties entirely, and provide a different way to achieve lazy
initialization.
2019-10-25 16:31:45 +02:00
Nikita Popov
184ba0c91c Remove recursive check from instanceof_interface
Parent interfaces are copied into the interface list during
inheritance, so there's no need to perform a recursive check.

Only exception are instanceof checks performed during inheritance
itself. However, we already have unlinked_instanceof for this
purpose, it just needs to be taught to handle this case.

Closes GH-4857.
2019-10-25 10:19:42 +02:00
Nikita Popov
cf85eb2468 Integrate property types with variance system
Property types are invariant, but may still have to load classes in
order to check for class aliases. This class loading should follow
the same rules as all other variance checks, rather than just
loading unconditionally.

This change integrates property type invariance checks into the
variance system as a new obligation type, and prevent early binding
if the type check cannot be performed.
2019-10-17 13:37:04 +02:00
Nikita Popov
f2e8851245 Remove func copy optimization for private method with static vars
Not NULLing the static_variables pointer for shadow methods during
static var shutdown would be a way to avoid this leak, but unless
there's evidence that inherited private methods with static vars are
actually a common use-case, I don't think we should keep this kind
of fragile edge-case optimization.

Fixes OSS-Fuzz #17875.
2019-10-01 13:04:06 +02:00
Nikita Popov
4b9ebd837b Allow throwing exception while loading parent class
This is a fix for symfony/symfony#32995.

The behavior is:

* Throwing exception when loading parent/interface is allowed
  (and we will also throw one if the class is simply not found).
* If this happens, the bucket key for the class is reset, so
  it's possibly to try registering the same class again.
* However, if the class has already been used due to a variance
  obligation, the exception is upgraded to a fatal error, as we
  cannot safely unregister the class stub anymore.
2019-09-12 16:41:18 +02:00
Nikita Popov
fbe287a677 Fix typo in unlinked_instanceof assertion 2019-09-11 16:50:16 +02:00
Nikita Popov
270e5e3c5b Only allow "nearly linked" classes for parent/interface
The requirements for parent/interface are difference than for the
variance checks in type declarations. The latter can work on fully
unlinked classes, but the former need inheritance to be essentially
finished, only variance checks may still be outstanding.

Adding a new flag for this because we have lots of space, but we
could also represent these "inheritance states" more compactly in
the future.
2019-09-11 16:27:28 +02:00
Nikita Popov
6cc53981e5 Addref static vars when not copying private method
While we don't need to give this method separate static vars, we
do still need to perform an addref, as there will be a corresponding
delref in the dtor.
2019-08-29 14:47:09 +02:00
Dmitry Stogov
e7446c1b2d Separate common code abd eliminate useless checks 2019-06-27 13:11:08 +03:00
Dmitry Stogov
a58964be82 Inline hot path 2019-06-27 11:27:53 +03:00
Dmitry Stogov
83b99527df Avoid double checks on early binding 2019-06-27 02:13:06 +03:00
Dmitry Stogov
36b7021e2c Private methods don't have to be duplicated 2019-06-26 13:27:13 +03:00
Dmitry Stogov
f7faa62c43 Reorder conditions to minimize number of checks on fast path 2019-06-26 01:00:31 +03:00
Dmitry Stogov
6288fc19dd Remove always true/false conditions, remove dead conde and simplify code. 2019-06-26 00:32:22 +03:00
Dmitry Stogov
215b5a7db8 Replace previosly checked conditions by ZEND_ASSERT() 2019-06-25 18:26:56 +03:00
Dmitry Stogov
f09d41ffc0 Fixed variance check for abstract constructor during erlay binding 2019-06-25 17:43:46 +03:00
Dmitry Stogov
ccbc121cb1 Cleanup 2019-06-25 16:37:42 +03:00
Dmitry Stogov
bd0cb99d8c Prevent useless hash lookups 2019-06-25 12:41:06 +03:00
Dmitry Stogov
759f4ecd8b Keep lowercased parent class name as second argument of DECLARE_CLASS to avoid extra work at run-time 2019-06-25 11:30:58 +03:00
Dmitry Stogov
0f29fb5cd8 Fixed bug 78175 (Preloading must store default values of static variables and properties) 2019-06-24 20:32:27 +03:00
Nikita Popov
8f8fcbbd39 Support full variance if autoloading is used
Keep track of delayed variance obligations and check them after
linking a class is otherwise finished. Obligations may either be
unresolved method compatibility (because the necessecary classes
aren't available yet) or open parent/interface dependencies. The
latter occur because we allow the use of not fully linked classes
as parents/interfaces now.

An important aspect of the implementation is we do not require
classes involved in variance checks to be fully linked in order for
the class to be fully linked. Because the involved types do have to
exist in the class table (as partially linked classes) and we do
check these for correct variance, we have the guarantee that either
those classes will successfully link lateron or generate an error,
but there is no way to actually use them until that point and as
such no possibility of violating the variance contract. This is
important because it ensures that a class declaration always either
errors or will produce an immediately usable class afterwards --
there are no cases where the finalization of the class declaration
has to be delayed until a later time, as earlier variants of this
patch did.

Because variance checks deal with classes in various stages of
linking, we need to use a special instanceof implementation that
supports this, and also introduce finer-grained flags that tell us
which parts have been linked already and which haven't.

Class autoloading for variance checks is delayed into a separate
stage after the class is otherwise linked and before delayed
variance obligations are processed. This separation is needed to
handle cases like A extends B extends C, where B is the autoload
root, but C is required to check variance. This could end up
loading C while the class structure of B is in an inconsistent
state.
2019-06-11 13:09:33 +02:00
Nikita Popov
89b2d88659 Register class before fetching parent
We want the class declaration to be available while compiling the
parent class.
2019-06-11 13:09:33 +02:00
Nikita Popov
e6fac86dc3 Accept flags argument in zend_lookup_class_ex()
Instead of a single boolean, so we have space for extension here.
2019-05-27 09:36:25 +02:00
Nikita Popov
49a3b03e9f Implement basic variance support
This is a minimal variance implementation: It does not support any
cyclic type dependencies. Additionally the preloading requirements
are much more restrictive than necessary. Hopefully we can relax
these in the future.
2019-05-24 09:30:37 +02:00
Nikita Popov
afec3a9208 Avoid early-binding on unresolved types
Fixes bug #76451, and more importantly lays necessary groundwork for
covariant/contravariant types. Bug #76451 is just an edge case, but
once covariance is introduced this will become a common problem instead.
2019-05-24 09:30:13 +02:00
Nikita Popov
64918c7702 Forbid use of not fully linked classes 2019-05-23 10:41:10 +02:00
Nikita Popov
f778e1a0b2 Refactor inheritance type check implementation
Extract the self/parent name resolution code and drop unnecessary
string copies/releases. Store the fe/proto types in local variables.
2019-05-08 12:13:06 +02:00
Nikita Popov
5c474010fb Deduplicate inheritance type check implementation
Make the check covariant (insofar as it is allowed now, i.e.
nullability and iterable) and call it with appropriate argument
order for both parameter and return types.

This makes it simpler to extend to full variance support.
2019-05-08 11:51:23 +02:00
Nikita Popov
d5ef9c5b28 Merge branch 'PHP-7.3' into PHP-7.4 2019-05-08 11:38:03 +02:00
Nikita Popov
e2ef4e9e2f Merge branch 'PHP-7.2' into PHP-7.3 2019-05-08 11:37:49 +02:00
Nikita Popov
d19b6aa5ba Fix resolution of "parent" during inheritance check
We can't assume that the method we're checking against is part of
the parent class...
2019-05-08 11:35:26 +02:00
Nikita Popov
0585548106 Treat abstract ctors the same, regardless of origin
Abstract ctor signatures should always be respected by all children,
independently of whether it comes from an interface or an abstract
class. Previously abstract ctor signatures (if they didn't come from
an interface) were only checked to one level of inheritance.
2019-03-27 18:09:09 +01:00
Nikita Popov
d1e5006c14 Fix lineno for more inheritance errors
And also include explicit linenos in tests.
2019-03-27 13:02:28 +01:00
Nikita Popov
251f293cb7 Make line numbers for inheritance errors more precise
Use the line of the conflicting child method, rather than either the
first or last line of the class.
2019-03-27 12:42:35 +01:00
Tyson Andre
da3316ff0f Fix typos in code comments in Zend/ [skip ci] 2019-02-18 17:56:28 +01:00
Nikita Popov
e6e9bea257 Avoid uninitialized entries in properties_info_table
Also don't place it into xlat, there's only ever one user.
2019-02-15 14:43:37 +01:00
Nikita Popov
3cafa7f4df Assign (un)serialize_func during compilation
This avoids writing this cache at runtime, which is illegal if
preloading is used.

Not every serialize/unserialize function actually belongs to the
Serializable interface, but I think it's not a problem to assign
these anyway -- whether they are used ultimately depends on whether
Serializable is implemented.

Alternatively it might make sense to just drop these entirely. I
don't think this is performance critical functionality.
2019-02-15 11:20:28 +01:00
Dmitry Stogov
43a7d95016 Fixed bug #77613 (method visibility change) (reverted ZEND_ACC_CTOR and ZEND_ACC_DTOR flags removal) 2019-02-14 13:12:50 +03:00
Nikita Popov
7a6fa7f624 Fix refcounting of prop types coming from traits 2019-02-08 12:20:31 +01:00
Peter Kokot
92ac598aab Remove local variables
This patch removes the so called local variables defined per
file basis for certain editors to properly show tab width, and
similar settings. These are mainly used by Vim and Emacs editors
yet with recent changes the once working definitions don't work
anymore in Vim without custom plugins or additional configuration.
Neither are these settings synced across the PHP code base.

A simpler and better approach is EditorConfig and fixing code
using some code style fixing tools in the future instead.

This patch also removes the so called modelines for Vim. Modelines
allow Vim editor specifically to set some editor configuration such as
syntax highlighting, indentation style and tab width to be set in the
first line or the last 5 lines per file basis. Since the php test
files have syntax highlighting already set in most editors properly and
EditorConfig takes care of the indentation settings, this patch removes
these as well for the Vim 6.0 and newer versions.

With the removal of local variables for certain editors such as
Emacs and Vim, the footer is also probably not needed anymore when
creating extensions using ext_skel.php script.

Additionally, Vim modelines for setting php syntax and some editor
settings has been removed from some *.phpt files.  All these are
mostly not relevant for phpt files neither work properly in the
middle of the file.
2019-02-03 21:03:00 +01:00
Zeev Suraski
a81202ac49 Adios, yearly copyright ranges 2019-01-30 11:48:28 +01:00
Nikita Popov
f78e681428 Fixed bug #77498
I've renamed the function to the same name as the exported symbol
in master.
2019-01-25 11:01:06 +01:00
Nikita Popov
e219ec144e Implement typed properties
RFC: https://wiki.php.net/rfc/typed_properties_v2

This is a squash of PR #3734, which is a squash of PR #3313.

Co-authored-by: Bob Weinand <bobwei9@hotmail.com>
Co-authored-by: Joe Watkins <krakjoe@php.net>
Co-authored-by: Dmitry Stogov <dmitry@zend.com>
2019-01-11 15:49:06 +01:00
Dmitry Stogov
cec091176c Replace zend_hash_apply... with ZEND_HASH_FOREACH... 2018-12-19 02:49:56 +03:00