Commit Graph

1066 Commits

Author SHA1 Message Date
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
Christoph M. Becker
6ee6097688 Constrain number parameter of numfmt_format to int|float
This is inline with similar changes to the math functions.  Especially,
array to number conversion makes no sense here, and is likely to hide
a programming error.

To make that feasible, we introduce the `n` specifier for classic ZPP
so we can stick with `zend_parse_method_parameters()`.

We also remove a test case, which has been degenerated to a ZPP test.
2020-02-16 16:48:35 +01:00
Nikita Popov
907ae8d4c6 Reset required_num_args for disabled functions
Otherwise we may get arginfo/zpp mismatch errors.
2020-02-12 12:01:22 +01:00
Nikita Popov
cb7b21009b Merge branch 'PHP-7.4'
* PHP-7.4:
  Reset trampoline on executor startup
  Fix UAF in is_callable() and allocated trampoline
2020-01-30 11:05:56 +01:00
Nikita Popov
429f194f40 Fix UAF in is_callable() and allocated trampoline
By nulling out the function_handler, so it will not get used
below. Reuse the existing helper for this purpose.
2020-01-30 11:04:59 +01:00
Nikita Popov
12fec7a14e Simplify constant updating for properties
Instead of walking up the parent chain, use the scope stored in
the property info. This way we only need to walk one list of
property infos.
2020-01-21 16:29:56 +01:00
Dmitry Stogov
6895eb4db5 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed memory leak
2019-12-17 10:09:43 +03:00
Dmitry Stogov
abf05181b9 Fixed memory leak 2019-12-17 10:09:22 +03:00
Dmitry Stogov
c8dbbd74e9 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed memory leaks
2019-12-17 09:58:56 +03:00
Dmitry Stogov
0927af3d8d Fixed memory leaks 2019-12-17 09:58:27 +03:00
Dmitry Stogov
ee45dbab37 Merge branch 'PHP-7.4'
* PHP-7.4:
  Addirional fix for bug #78918
2019-12-11 12:29:10 +03:00
Dmitry Stogov
3280209c03 Addirional fix for bug #78918 2019-12-11 12:21:49 +03:00
Nikita Popov
aaa0a80636 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix build
2019-12-09 16:06:37 +01:00
Nikita Popov
8d36d79d57 Fix build 2019-12-09 16:06:26 +01:00
Dmitry Stogov
62826e95d2 Merge branch 'PHP-7.4'
* PHP-7.4:
  Call zend_unregister_ini_entries() when unload extension loaded through dl() without MSHUTDOWN callback. Extensions with MSHUTDOWN should use UNREGISTER_INI_ENTRIES().
2019-12-09 15:07:39 +03:00
Dmitry Stogov
92c23e1fd3 Call zend_unregister_ini_entries() when unload extension loaded through dl() without MSHUTDOWN callback.
Extensions with MSHUTDOWN should use UNREGISTER_INI_ENTRIES().
2019-12-09 15:05:24 +03:00
Nikita Popov
a298bde9fb Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78898
2019-12-04 09:41:51 +01:00
Nikita Popov
6540797f1e Fixed bug #78898 2019-12-04 09:40:48 +01:00
Dmitry Stogov
0f2b6ece4e Merge branch 'PHP-7.4'
* PHP-7.4:
  Fixed bug #78868 (Calling __autoload() with incorrect EG(fake_scope) value)
  Consolidate NEWS for 7.4.0 release
  WIP: Merge NEWS
2019-11-25 14:10:53 +03:00
Dmitry Stogov
2ebf530946 Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fixed bug #78868 (Calling __autoload() with incorrect EG(fake_scope) value)
2019-11-25 14:09:18 +03:00
Dmitry Stogov
bb30fe9e2b Fixed bug #78868 (Calling __autoload() with incorrect EG(fake_scope) value) 2019-11-25 14:05:43 +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
Máté Kocsis
14bdb0cfc7 Fix consistency issues with array accesses warnings/exceptions
* Change a number of "resource used as offset" notices to warnings,
   which were previously missed.
 * Throw the "resource used as offset" warning for isset() as well.
 * Make array_key_exists() behavior with regard to different key
   types consistent with isset() and normal array accesses. All key
   types now use the usual coercions and array/object keys throw
   TypeError.

Closes GH-4887.
2019-11-06 12:56:47 +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
Nikita Popov
e63a44dd03 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix bug #78226: Don't call __set() on uninitialized typed properties
2019-10-25 16:32:14 +02: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
c858d17f06 Optimize instanceof_function
Split out the simple equality check into an inline function --
this is one of the common cases.

Replace instanceof_function_ex with zend_class_implements_interface.
There are a few more places where it may be used.
2019-10-25 10:51:17 +02:00
Nikita Popov
fea482ee5c Merge branch 'PHP-7.4' 2019-10-10 12:45:38 +02:00