Commit Graph

833 Commits

Author SHA1 Message Date
Nikita Popov
a0abc26ef7 Add get_resource_id() function
Behavior is same as for (int) $resource, just under a clearer
name. Also type-safe, in that the parameter actually needs to
be a resource.

Closes GH-5427.
2020-05-11 12:04:16 +02:00
Tyson Andre
d63eca285a
Fix miscellaneous typos in code comments/var names
Closes GH-5501
2020-05-01 15:49:05 +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
292085f336 Generate zend_builtin_functions FEs from stubs 2020-04-21 12:23:56 +02:00
Nikita Popov
d68dfaf05e Remove return value from llist apply functions
Unlike the hash apply functions, these do not return int.
2020-04-15 11:01:12 +02:00
Christoph M. Becker
e6458d67cf Fix #79462: method_exists and property_exists incoherent behavior
Both functions are closely related, so should behave the same for wrong
input types, i.e. both should throw a TypeError.
2020-04-09 11:38:47 +02:00
George Peter Banyard
55a3e5b99e Promote some warnings to Errors in Zend basic functions
Closes GH-5325
2020-03-31 16:32:58 +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
Nikita Popov
fbe19a6eb7 Clarify that return throws 2020-03-30 16:27:38 +02:00
Nikita Popov
295895342f Remove unnecessary NULL check
This is a required zpp parameter, it cannot be null.
2020-03-30 12:24:39 +02: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
b4c74c54b2 Merge branch 'PHP-7.4'
* PHP-7.4:
  Fix #63206: Fully support error/exception_handler stacking, even with null or inside the handler
2020-02-25 12:44:26 +01:00
Nikita Popov
1e50c81f6f Merge branch 'PHP-7.3' into PHP-7.4
* PHP-7.3:
  Fix #63206: Fully support error/exception_handler stacking, even with null or inside the handler
2020-02-25 12:44:11 +01:00
Mark Plomer
8c6a7c3326 Fix #63206: Fully support error/exception_handler stacking, even with null or inside the handler
Always push the current user_error/exception_handler to the stack,
even when it is empty, so restore_error_handler() always works as
expected.

The user_error_handler is especially temporarily empty when we are inside
the error handler, which caused inconsistent behaviour before.
2020-02-25 12:43:42 +01:00
Máté Kocsis
ac0853eb26
Make type error messages more consistent
Closes GH-5092
2020-02-17 14:22:17 +01:00
Máté Kocsis
8f4f1dea34
Convert zend_parse_parameters_none() to fast ZPP
I've done the conversion in those extensions where fast ZPP is predominant.
2020-01-03 13:23:37 +01:00
Máté Kocsis
e1b57310b1
Use RETURN_THROWS() during ZPP in main, sapi, win32, and Zend 2019-12-30 17:38:10 +01:00
Xinchen Hui
3f3c1ad848 Merge branch 'PHP-7.4'
* PHP-7.4:
  Similar problem (#79022) also exists in Interfaces
  Fixed bug #79022 (class_exists returns True for classes that are not ready to be used)
2019-12-24 14:21:52 +08:00
Xinchen Hui
f09b958e90 Similar problem (#79022) also exists in Interfaces 2019-12-24 14:20:55 +08:00
Xinchen Hui
153c9cc346 Fixed bug #79022 (class_exists returns True for classes that are not ready to be used) 2019-12-24 14:04:19 +08:00
Máté Kocsis
0e8070778e
Make get_defined_vars() always return an array
GH-5025
2019-12-20 14:31:57 +01:00
Máté Kocsis
2204dbde3b Add missing ZPP checks
Closes GH-4878.
2019-11-01 15:26:52 +01:00
Nikita Popov
fec0ff8cb0 Merge branch 'PHP-7.4' 2019-10-04 12:42:58 +02:00
Nikita Popov
ca652aafa8 Fixed bug #78632
I'm going for a very conservative fix here, where the previous
logic is restored for the case where an object is passed to
method_exists(). We might want to check against EG(scope) instead,
but this seems like a safer choice.

This means that behavior in PHP 7.4 changes only for
method_exists('C', 'privateMethodNotOnC'), which should be sensible.
2019-10-04 12:41:49 +02:00
Nikita Popov
cc4af3513d Merge branch 'PHP-7.4' 2019-09-03 13:59:59 +02:00
Nikita Popov
6255308624 Report false for inherited private methods in method_exists()
These shadow methods only exist as internal implementation markers.
This mirrors the behavior of property_exists().
2019-09-03 13:59:25 +02:00
Nikita Popov
d93b094584 Throw TypeError from VM implementation of get_class()
The normal function already throws TypeError through the usual zpp
mechanism, but the VM implementation handles this manually and has
not been updated.
2019-08-27 09:37:48 +02:00
Nikita Popov
33886f710c Generate arginfo from PHP stub files
Signature stubs for internal functions are specified in xyz.stub.php,
from which we generate actual arginfo structures in xyz_arginfo.h.
This file then needs to be included in the implementation appropriately.

Arginfo from stubs can be regenerated using scripts/dev/gen_stub.php.
However, this should also automatically happen when the stub file is
modified.
2019-08-09 14:51:25 +02:00
Nikita Popov
8aa92c1465 Merge branch 'PHP-7.4' 2019-07-24 10:52:18 +02:00
Nikita Popov
a49d53baa2 Don't skip uninitialized typed props in get_class_vars()
For bug #78319.
2019-07-24 10:52:01 +02:00
Nikita Popov
227a9c75ec Add types to a couple of builtin functions 2019-06-17 14:47:20 +02:00
Nikita Popov
7d98dd9c1c Merge branch 'PHP-7.4' 2019-06-11 10:29:20 +02:00
Nikita Popov
eecd8961d9 Add get_mangled_object_vars() function 2019-06-11 10:28:29 +02:00
Nikita Popov
252216b2de Remove possible false return value from get_object_vars()
I'm not sure this one ever happens in practice (and we might want
to forbid NULL return from get_properties), but if it does, return
an empty array instead of false.
2019-06-06 09:49:25 +02:00
Dmitry Stogov
e029cc4dd4 Merge branch 'PHP-7.4'
* PHP-7.4:
  Cheaper checks for exceptions thrown from __toString()
2019-06-06 02:23:17 +03:00
Dmitry Stogov
457392fa64 Cheaper checks for exceptions thrown from __toString() 2019-06-06 01:47:22 +03:00
Nikita Popov
7686b0b889 Merge branch 'PHP-7.4' 2019-06-05 14:53:50 +02:00
Nikita Popov
a31f46421d Allow exceptions in __toString()
RFC: https://wiki.php.net/rfc/tostring_exceptions

And convert some object to string conversion related recoverable
fatal errors into Error exceptions.

Improve exception safety of internal code performing string
conversions.
2019-06-05 14:25:07 +02:00
Nikita Popov
45a0656e95 Remove get() object handler
Now that set() is gone, there is little point in keeping get(), as
it is essentially just a different way of writing cast_object()
now.

Closes GH-4202.
2019-05-29 17:15:19 +02:00
Dmitry Stogov
c64fe84f8b Merge branch 'PHP-7.4'
* PHP-7.4:
  Avoid double copying
2019-05-28 13:35:29 +03:00
Dmitry Stogov
b2cb6a4a27 Avoid double copying 2019-05-28 13:35:00 +03:00
Nikita Popov
1493c73582 Update MAY_BE_NULL func_info for Zend functions
These cannot return NULL anymore in PHP 8.
2019-05-28 11:43:23 +02:00
Nikita Popov
13f675b858 Merge branch 'PHP-7.4' 2019-05-27 09:38: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
20e983d9ce Merge branch 'PHP-7.4' 2019-05-14 14:59:36 +02:00
Nikita Popov
3f19f5112a Add RETURN_EMPTY_ARRAY() / RETVAL_EMPTY_ARRAY()
The usual wrappers around ZVAL_EMPTY_ARRAY()...
2019-05-14 14:59:10 +02:00
Nikita Popov
8ccdb8282e Merge branch 'PHP-7.4' 2019-03-22 09:48:26 +01:00
rjhdby
5456a6ea92 Deduplicate code in zend_builtin_functions.c 2019-03-22 09:47:09 +01:00
Nikita Popov
1016e3a927 Merge branch 'PHP-7.4' 2019-02-19 10:07:47 +01:00