Skip to content

Commit f5db313

Browse files
committed
zend_is_callabel changes on master + nits
1 parent 9d11af9 commit f5db313

1 file changed

Lines changed: 33 additions & 31 deletions

File tree

‎docs/source/core/data-structures/fci-fcc.rst‎

Lines changed: 33 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -71,21 +71,21 @@ There are some functions that do not require the use of either the FCI or the FC
7171

7272
- - .. code:: c
7373

74-
zend_is_callable(
75-
zval *callable,
76-
uint32_t check_flags,
77-
zend_string **callable_name
74+
bool zend_is_callable(
75+
const zval *callable,
76+
zend_fcall_info_cache *fcc,
77+
char **error
7878
)
7979
8080
- Check if the ``callable`` zval is a PHP callable. Returns true if it is, false otherwise.
81-
``check_flags`` is a bit mask of ``IS_CALLABLE_CHECK_SYNTAX_ONLY`` and
82-
``IS_CALLABLE_SUPPRESS_DEPRECATIONS``, generally should be left to 0. ``callable_name`` is
83-
an optional out parameter, it will be set to the string representation of the ``callable``
84-
zval, set even in case of failure.
81+
``fcc`` is an out parameter constructing the FCC struct, see below for details. ``error``
82+
is an optional out parameter holding the error message if ``callable`` is not a PHP
83+
callable. Note: the signature used to be ``bool zend_is_callable(zval *callable, uint32_t
84+
check_flags, zend_string **callable_name)`` prior to PHP 8.7.
8585

8686
- - .. code:: c
8787

88-
zend_is_callable_ex(
88+
bool zend_is_callable_ex(
8989
zval *callable,
9090
zend_object *object,
9191
uint32_t check_flags,
@@ -96,9 +96,10 @@ There are some functions that do not require the use of either the FCI or the FC
9696
9797
- Same as ``zend_is_callable()`` with additional arguments. ``object`` if ``callable`` is a
9898
string, this ``zend_object*`` represents the class instance to check if such a method
99-
exists. ``fcc`` is an out parameter constructing the FCC struct, see below for details.
100-
``error`` is an optional out parameter holding the error message if ``callable`` is not a
101-
PHP callable.
99+
exists. ``check_flags`` is a bit mask of ``IS_CALLABLE_CHECK_SYNTAX_ONLY`` and
100+
``IS_CALLABLE_SUPPRESS_DEPRECATIONS``, generally should be left to 0. ``callable_name`` is
101+
an optional out parameter, it will be set to the string representation of the ``callable``
102+
zval, set even in case of failure.
102103

103104
- - .. code:: c
104105

@@ -189,10 +190,10 @@ There are some functions that do not require the use of either the FCI or the FC
189190
zval *params
190191
)
191192
192-
- Returns ``FAILURE`` if the ``method_name`` does not exists on the object,
193-
``SUCCESS`` otherwise.
194-
The retval *will* be UNDEF if the return value is ``FAILURE```, as such the
195-
retval can be unconditionally destroyed. However it may also be UNDEF in an exception was thrown.
193+
- Returns ``FAILURE`` if the ``method_name`` does not exists on the object, ``SUCCESS``
194+
otherwise. The retval *will* be UNDEF if the return value is ``FAILURE```, as such the
195+
retval can be unconditionally destroyed. However it may also be UNDEF in an exception was
196+
thrown.
196197

197198
- - .. code:: c
198199

@@ -205,11 +206,11 @@ There are some functions that do not require the use of either the FCI or the FC
205206
params
206207
)
207208

208-
- Deprecated API. Checks that ``function_name`` (and optionally ``object``) is a valid PHP callable via
209-
``zend_is_callable_ex()`` and calls it with the given parameters and return value.
210-
``function_table`` is ignored and should always be ``NULL``. It is recommended to instead
211-
use ``zend_is_callable_ex()`` to fetch an FCC and call it with ``zend_call_known_fcc()``,
212-
see below for more details.
209+
- Deprecated API. Checks that ``function_name`` (and optionally ``object``) is a valid PHP
210+
callable via ``zend_is_callable_ex()`` and calls it with the given parameters and return
211+
value. ``function_table`` is ignored and should always be ``NULL``. It is recommended to
212+
instead use ``zend_is_callable()`` to fetch an FCC and call it with
213+
``zend_call_known_fcc()``, see below for more details.
213214

214215
- - .. code:: c
215216

@@ -266,16 +267,17 @@ There are some functions that do not require the use of either the FCI or the FC
266267
didn't exist.
267268

268269
FCCs are the goto structure to handle and store PHP callables as most of the time they don't need
269-
any reference counting. The one exception is the FCC represents a trampoline. A trampoline is a call
270-
to a non existing class method handled by the ``__call()`` or ``__callStatic()`` magic methods. When
271-
a trampoline is created it allocates a ``zend_function`` struct with the op array copied, and freed
272-
when called. However the ``f`` ZPP argument specifier will *free* the trampoline and assign ``NULL``
273-
to ``function_handler``, making the FCC uninitialized. The trampoline can be manually fetched by
274-
using ``zend_is_callable_ex()`` or to prevent ZPP from freeing it one can use the ``F`` argument
275-
specifier`. However, in that case careful consideration need to be done to free the potential
276-
trampoline in any failure path, including ZPP failure.
277-
278-
The *only* case where an FCC will be uninitialized is if the function is a trampoline, i.e. when the
270+
any reference counting. The one exception is when the FCC represents a trampoline. A trampoline is a
271+
heap-allocated `zend_function*`, the most common trampolines are calls to a non existing class
272+
method handled by the ``__call()`` or ``__callStatic()`` magic methods. A trampoline releases the
273+
``zend_function*`` when it is called, as the op array will be consumed. However the ``f`` ZPP
274+
argument specifier will *free* the trampoline and assign ``NULL`` to ``function_handler``, making
275+
the FCC uninitialized. The trampoline can be manually fetched by using ``zend_is_callable()`` or to
276+
prevent ZPP from freeing it one can use the ``F`` argument specifier`. However, in that case careful
277+
consideration need to be done to free the potential trampoline in any failure path, including ZPP
278+
failure.
279+
280+
The *only* case where an FCC may be uninitialized is if the function is a trampoline, i.e. when the
279281
method of a class does not exist but is handled by the magic methods
280282
``__call()``/``__callStatic()``. This is because a trampoline is freed by ZPP as it is a newly
281283
allocated ``zend_function`` struct with the op array copied, and is freed when called. To retrieve

0 commit comments

Comments
 (0)