Commit Graph

1094 Commits

Author SHA1 Message Date
Nikita Popov
236ddc56a2 Preserve original ce_flags when registering class
Bug that regularly sneaks in: ZEND_ACC_FINAL is set before calling
zend_register_internal_class() and promptly gets ignored. Remove
this footgun by preserving flags from the original CE.
2020-07-20 17:00:04 +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
Nikita Popov
efce3694b7 Directly assign magic methods
Instead of going through intermediary variables.
2020-07-20 11:22:47 +02:00
Nikita Popov
91e5452b95 Remove unused lc_class_name variable
This is probably a leftover from "old style constructor" support.
2020-07-20 11:15:58 +02:00
Nikita Popov
19de727e04 Report magic method names as written
Report the name the way the user has written it, the same way we
always do.
2020-07-20 11:12:47 +02:00
Nikita Popov
149029b9d6 Unify magic method visibility check
This was missing entirely for the internal function case.
2020-07-20 11:12:47 +02:00
Nikita Popov
312fe2bdce Unify magic method return type checks 2020-07-20 10:51:48 +02:00
Nikita Popov
fbbcf82ab7 Unify static/non-static check for magic methods
And promote it to be fatal.
2020-07-20 10:39:43 +02:00
Nikita Popov
b466e8b754 Add missing arg num check for __set_state 2020-07-20 10:20:29 +02:00
Nikita Popov
dcaf62f3d3 Clean up zend_check_magic_method_implementation
Let everything go through a common function, which fixes some
consistency issues.
2020-07-20 10:17:40 +02:00
George Peter Banyard
4f3eccfd4d Use consistent types
uint32_t type for argument count
size_t for length of char*
zend_bool for a zval bool arg

Closes GH-5845
2020-07-13 13:30:54 +02:00
Máté Kocsis
d30cd7d7e7
Review the usage of apostrophes in error messages
Closes GH-5590
2020-07-10 21:05:28 +02:00
twosee
b284ba3943 Add zend_wrong_parameter_error to reduce the size of ZPP macro
Closes GH-5831.
2020-07-10 10:12:23 +02:00
George Peter Banyard
9839752a9c Voidify some ZEND_API functions
Closes GH-5805
2020-07-09 14:15:57 +02:00
Nikita Popov
302933daea Remove no_separation flag 2020-07-07 09:30:24 +02:00
Máté Kocsis
b18b2c8fe5
Add string or object ZPP macros
Closes GH-5788
2020-07-06 12:42:02 +02: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
twosee
05ed7bff17 Make zend_argument_error_variadic static
Closes GH-5687
2020-06-09 00:42:48 +02:00
twosee
88355dd338 Constify char * arguments of APIs
Closes GH-5676.
2020-06-08 10:38:45 +02:00
twosee
7d6a0ba808 Fix expression warnings and break warnings
Close GH-5675.
2020-06-07 10:41:11 +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
Nikita Popov
aaae77f7f1 Make Exception::$trace typed array property
This is a private property, so we are allowed to add a type.
The new declaration of the property is:

    private array $trace = [];

This ensures that Exception::getTrace() does indeed return an array.

Userland code that was modifying the property through refleciton
may have to be adjusted to assign an array (instead of null,
for example).

Closes GH-5636.
2020-05-28 13:55:38 +02:00
Máté Kocsis
fbe30592d6
Improve type error messages when an object is given
From now on, we always display the given object's type instead of just reporting "object".
Additionally, make the format of return type errors match the format of argument errors.

Closes GH-5625
2020-05-26 19:06:19 +02:00
George Peter Banyard
cebe750f46 Refactor ZPP API to use uint32_t as everywhere else
Closes GH-5609
2020-05-22 17:13:42 +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
Máté Kocsis
1179686f62
Improve error messages for invalid property access
Closes GH-5446
Co-authored-by:  Nikita Popov <nikita.ppv@gmail.com>
2020-05-18 08:27:00 +02:00
Nikita Popov
87e6f93fd6 Assert on unknown type in zend_get_type_by_const() 2020-05-13 15:03:44 +02:00
Nikita Popov
3f51d82bca Rename zend_zval_get_type() API
We have a bunch of APIs for getting type names and it's sometimes
hard to keep them apart ... make it clear that this is the one
you definitely do not want to use.
2020-05-13 14:56:05 +02:00
George Peter Banyard
7b74fc7a7b Add Fast ZPP string|int type check 2020-05-02 19:50:51 +02:00
Nikita Popov
53eee290b6 Completely remove disabled functions from function table
Currently, disabling a function only replaces the internal
function handler with one that throws a warning, and a few
places in the engine special-case such functions, such as
function_exists. This leaves us with a Schrödinger's function,
which both does not exist (function_exists returns false) and
does exist (you cannot define a function with the same name).
In particular, this prevents the implementation of robust
polyfills, as reported in https://bugs.php.net/bug.php?id=79382:

    if (!function_exists('getallheaders')) {
        function getallheaders(...) { ... }
    }

If getallheaders() is a disabled function, this code will break.

This patch changes disable_functions to remove the functions from
the function table completely. For all intents and purposes, it
will look like the function does not exist.

This also renders two bits of PHP functionality obsolete and thus
deprecated:

 * ReflectionFunction::isDisabled(), as it will no longer be
   possible to construct the ReflectionFunction of a disabled
   function in the first place.
 * get_defined_functions() with $exclude_disabled=false, as
   get_defined_functions() now never returns disabled functions.

Fixed bug #79382.

Closes GH-5473.
2020-04-30 09:53:57 +02:00
Nikita Popov
533669f7c4 Remove redundant addref+dtor 2020-04-29 10:27:35 +02:00
Nikita Popov
fd00c7cf10 Pass existing lcname to check_magic_method_implementation 2020-04-27 12:33:29 +02:00
Gabriel Caruso
74f1547591 Use zend_string in zend_check_magic_method implementation 2020-04-27 12:23:37 +02:00
Gabriel Caruso
6f908a0bf4
Check Serialization magic methods structure
Closes GH-5441
2020-04-26 02:16:39 +02:00
Nikita Popov
08c5c69eff Remove ZEND_ACC_DTOR flag
This is only used in reflection, where doing a simple string check
is acceptable.

I'm also dropping the "dtor" printing in the reflection dump.
Dtors are just one of many magic methods, I don't think there's
a point in explicitly highlighting them, when the name is already
unambiguous.
2020-04-17 15:32:47 +02:00
Gabriel Caruso
add8c15a31
Align magic methods' camelCase with documentation
Closes GH-5398
2020-04-16 13:53:13 +02:00
Nikita Popov
4fb705a03d Add zend_string_concat2 API 2020-04-14 17:18:05 +02:00
Nikita Popov
4a935bc2c9 Always use __invoke callable name for objects
The callable name is provided also if it's not callable, in which
case it's basically "what it would be if it were callable", which
is ClassName::__invoke. The current behavior of casting the object
to string makes very little sense as this will just throw an
exception for most objects.
2020-04-14 17:02:47 +02:00
Nikita Popov
bac5137e4e Add zend_create_member_string() API
This is a recurring pattern.
2020-04-14 16:52:13 +02:00
Nikita Popov
d030ddb2cd Export the zend_string_concat3() API 2020-04-09 15:06:53 +02:00
Nikita Popov
696ae335e3 Export API for fetching internal func default
Make this functionality available outside reflection.
2020-04-09 14:55:55 +02:00
Nikita Popov
c81cf1c7af Assert that arginfo parameter name is present 2020-04-07 16:05:33 +02:00
Máté Kocsis
b6229fbca2
Display nullability in type error messages for internal functions
Closes GH-5327
2020-03-31 16:55:36 +02:00
Nikita Popov
8fd7f02ea4 Make cast_object handler required
Avoid subtle differences in behavior depending on whether the
handler is absent or returns FAILURE.

If you previously set cast_object to NULL, create a handler that
always returns FAILURE instead.
2020-03-31 14:37:49 +02:00
Máté Kocsis
bb6f374048
Improve argument error messages in ext/standard
Closes GH-5198
2020-03-18 19:56:10 +01:00
Nikita Popov
9c6e206bce Remove NO_ACCESS flag for zend_is_callable()
We may add support for fake_scope if necessary.
2020-03-06 16:31:03 +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
Máté Kocsis
960318ed95
Change argument error message format
Closes GH-5211
2020-02-26 15:00:08 +01:00
Nikita Popov
b35b0142e6 Require all internal functions to have arginfo 2020-02-26 10:05:20 +01:00
Máté Kocsis
ac0853eb26
Make type error messages more consistent
Closes GH-5092
2020-02-17 14:22:17 +01:00