Commit graph

1061 commits

Author SHA1 Message Date
Nikita Popov
42fbc76d9c Always invoke zpp in ReflectionProperty::getValue/isInitialized
Make sure we still perform a zpp check for the static case, and
also always enforce that the parameter is ?object. Otherwise we
violate the specified signature.
2020-02-10 11:05:26 +01:00
Nikita Popov
87f127d8fa Rename reflection stub file
Where possible, the stub file should match the name of the C file,
so that the build system integration automatically recompiles it.
2020-02-10 10:53:44 +01:00
George Peter Banyard
c343c1bcae Fix some -Wold-style-declaration compiler warnings 2020-02-05 17:39:29 +01:00
Nikita Popov
58b17906f5 Apply tidy formatting
Mostly reindent PHP scripts to spaces.
2020-02-03 13:41:31 +01:00
Benjamin Eberlei
7a52bf21d3 Add ReflectionProperty::getDefaultValue and ReflectionProperty::hasDefaultValue 2020-01-22 21:24:36 +01:00
Nikita Popov
1f1a7ecaf2 Simplify ReflectionProperty::getDeclaringClass() 2020-01-21 15:21:07 +01:00
Nikita Popov
117b18d22d Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #79115
2020-01-17 11:38:18 +01:00
Nikita Popov
384dfe331b Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #79115
2020-01-17 11:38:10 +01:00
Nikita Popov
07bda97e76 Fixed bug #79115 2020-01-17 11:37:35 +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
1fa6f03265 Fix reflection leak if type inside type list is resolved 2020-01-16 15:30:24 +01:00
Máté Kocsis
aadd3aaed9
Use RETURN_THROWS() in various places 2020-01-03 21:10:24 +01:00
Máté Kocsis
7b4a4d2ace
Use RETURN_THROWS() after try_convert_to_string() 2020-01-03 17:04:06 +01:00
Máté Kocsis
763788afea
Use RETURN_THROWS() after zend_throw_exception() in reflection extension 2020-01-03 10:18:34 +01:00
Máté Kocsis
349a286461
Use RETURN_THROWS() after zend_throw_error() 2020-01-01 16:42:30 +01:00
Máté Kocsis
9099dbd961
Use RETURN_THROWS() after zend_type_error() 2020-01-01 14:23:21 +01:00
Máté Kocsis
817605917b
Use RETURN_THROWS() during ZPP in the remaining extensions
In reflection, sodium, and SPL
2019-12-31 16:33:02 +01:00
Dmitry Stogov
796d11c942 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78895 (Reflection detects abstract non-static class as abstract static. IS_IMPLICIT_ABSTRACT is not longer used)
2019-12-09 13:50:43 +03:00
Dmitry Stogov
42a2fb8411 Fixed bug #78895 (Reflection detects abstract non-static class as abstract static. IS_IMPLICIT_ABSTRACT is not longer used) 2019-12-09 13:49:12 +03:00
Nikita Popov
999e32b65a Implement union types
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.
2019-11-08 15:15:48 +01:00
Nikita Popov
ac4e0f0852 Make zend_type a 2-field struct
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.
2019-11-08 15:15:48 +01:00
Nikita Popov
5b447d4b42 Remove dead code related to inherits props in reflection
Public/protected properties defined in parent classes will be
inherited in the child -- there is no need to explicitly try to
walk up the chain and look them up.
2019-11-04 11:24:32 +01:00
Nikita Popov
0e3045ae69 Store pointer to property_info in reflection
Instead of constructing a dummy property_info for dynamic properties,
leave the field as NULL and handle this as appropriate.

This was originally part of an alternative fix for bug #78774, but
I think doing it this way is generally preferrable independently
of that.
2019-11-04 11:08:19 +01:00
Nikita Popov
7f9e7399d3 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78774
2019-11-04 11:04:11 +01:00
Nikita Popov
c9abfaec6b Fixed bug #78774
The string held by the zend_type may be released if the property
type gets resolved to a CE. I initially wanted to fix this by
storing a zend_type* instead (so the property type resolution
propagates to the ReflectionType), but decided against this in
light of upcoming union types support, where we also need to
represent parts of the union, and will not have a single zend_type*
we can reference.
2019-11-04 11:04:02 +01:00
Christoph M. Becker
4008704f62 zend_parse_parameters_throw() is obsolete
Since `zend_parse_parameters()` throws now, there is no reason to
explicitly call `zend_parse_parameters_throw()` anymore, and since both
have actually the same implementation, we redefine the latter as macro.
2019-11-01 16:47:15 +01:00
Christoph M. Becker
b897d19552 Add missing zend_parse_parameters_none()
We fix the trivial cases; some others need further discussion, see
<https://news-web.php.net/php.internals/107723>.
2019-10-28 16:18:15 +01:00
Christoph M. Becker
addc78f379 Revert "Add missing zend_parse_parameters_none()"
This reverts commit ef439ec895.
Test failures need to be resolved first.
2019-10-27 13:41:41 +01:00
Christoph M. Becker
ef439ec895 Add missing zend_parse_parameters_none() 2019-10-27 13:12:45 +01:00
Thomas Gerbet
c9fc076a75 Add stubs for ext-reflection 2019-10-26 12:32:12 +02:00
Nikita Popov
530a8a3854 Fix and undeprecate ReflectionType::__toString()
Add deprecated _ZendTestClass::__toString() method to preserve
an existing test.

ReflectionType::__toString() will now return a complete
representation of the type, as it should have originally. Users
that relied on nullability being absent should have been pushed
to ReflectionNamedType::getName() by the deprecation of
ReflectionType::__toString() in PHP 7.1 / PHP 7.4.
2019-10-22 11:26:02 +02:00
Joe Watkins
174ab25fd4
Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix bug #78697: inaccurate error message
2019-10-21 09:25:24 +02:00
Joe Watkins
1ac961bea8
Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix bug #78697: inaccurate error message
2019-10-21 09:24:41 +02:00
Joe Watkins
1c9b62fbd4
Merge branch 'PHP-7.2' into PHP-7.3
* PHP-7.2:
  Fix bug #78697: inaccurate error message
2019-10-21 09:23:26 +02:00
Fabien Villepinte
bea2ff88c9
Fix bug #78697: inaccurate error message 2019-10-21 09:22:09 +02:00
Nikita Popov
c9d4696f76 Merge branch 'PHP-7.4' 2019-10-07 16:32:42 +02:00
Nikita Popov
f085bddb51 Fix number of required arguments in arginfo
* pack() only requires one argument
* stream_context_set_option() only requires two arguments
* ReflectionMethod::getClosure() accepts no args for static methods
* DOMDocument::createProcessingInstruction() only requires one arg
* DOMImplementation::createDocument() only requires two arguments
* DOMDocument::importNode() only requires one arg
* mysql_get_client_version() doesn't accept any args,
  despite what the docs say...
2019-10-07 16:32:11 +02:00
Gabriel Caruso
5d6e923d46
Remove mention of PHP major version in Copyright headers
Closes GH-4732.
2019-09-25 14:51:43 +02:00
Christoph M. Becker
0c7124e6be Add check_only parameter to get_closure handler
`get_closure` handlers are called to check whether an object is
callable, and to actually get the closure, respectively.  The behavior
of the handler might differ for these two cases, particularly the
handler may throw in the latter case, but should not in the former.

Therefore we add a `check_only` parameter, to be able to distinguish
the desired purpose.
2019-09-24 16:08:42 +02:00
Nikita Popov
6276dd826b Use ZEND_TYPE_IS_SET() when checking for property types
Instead of a simple if or 0 comparison. This would no longer work
if zend_type is a struct.
2019-09-23 16:53:54 +02:00
Nikita Popov
3012d006ff Don't set nullability flag for parameters without type
Use value 0 instead. To compensate we check in ReflectionParameter
allowsNull() whether the type is set at all: If it isn't, it always
allows null.

This removes a discrepancy between internal&userland functions:
For userland functions allowsNull() on untyped parameters returned
true, but for internal functions it returned false.
2019-09-23 16:39:52 +02:00
Nikita Popov
8d7911ef56 Standardize type printing in reflection
Use ?T instead of "T or NULL".
2019-09-23 15:40:03 +02:00
Nikita Popov
9e8ba7891e Change representation of zend_type from type code to MAY_BE_* mask
This switches zend_type from storing a single IS_* type code to
storing a MAY_BE_* type mask. Right now most code still assumes
that there is only a single type in the mask (or two together
with MAY_BE_NULL). But this will make it a lot simpler to introduce
union types.

An additional advantage (and why I'm doing this separately), is
that a number of special cases no longer need to be handled
separately: We can do a single mask & (1 << type) check to handle
all simple types, booleans (true|false) and null.
2019-09-23 15:31:35 +02:00
Nikita Popov
4fc4249d24 Make ReflectionType an abstract class
This is never instantiated directly, only child classes are used.
2019-09-02 15:38:56 +02:00
Nikita Popov
bdf2cd7508 Move isBuiltin() method from ReflectionType to ReflectionNamedType
This method only makes sense for single types, e.g. it would be
meaningless for union types.

Note that we always return ReflectionNamedType right now, so this does
not break compatibility for code using any currently existing types.
2019-09-02 14:59:31 +02:00
Nikita Popov
d0f4ec4c31 Merge branch 'PHP-7.4' 2019-08-13 20:24:39 +02:00
Nikita Popov
d891b5f458 Fixed bug #78410 2019-08-13 20:23:56 +02:00
Nikita Popov
7a1540fa28 Merge branch 'PHP-7.4' 2019-07-22 17:00:17 +02:00
Nikita Popov
c817b8020c Special-case rc=1 self-referential arrays in ReflectionReference
New fix for bug #78263. This is special-cased elsewhere in the engine,
so we need to mirror it here.
2019-07-22 16:59:23 +02:00
Nikita Popov
19588a8f3b Revert "Add ReflectionReference::getRefcount()"
This reverts commit 428cfdd181.
2019-07-22 16:49:08 +02:00