Skip to content

Commit 31314f0

Browse files
committed
Add note about comparing functions
1 parent b204256 commit 31314f0

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Book/php7/internal_types/functions/callables.rst

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,12 @@ op array copied, and is freed when called. To retrieve it manually use ``zend_is
9797
and released as needed. Moreover, if the callable is a trampoline the ``function_handler`` must be copied
9898
to be persisted between calls (see how SPL implements the storage of autoloading functions).
9999

100+
.. note:: To determine that two user functions are equal comparing the ``function_handler``, ``object``,
101+
``called_scope``, ``calling_scope``, and the pointer to the ``zend_object`` for closures is generally sufficient.
102+
Except when the user function is a trampoline, this is because the ``function_handler`` is reallocated for every
103+
call, in that case one needs to compared the ``function_handler->common.function_name`` field using
104+
``zend_string_equals()`` instead of comparing the pointers of the function handler directly.
105+
100106
.. note:: In most cases an FCC does not need to be released, the exception is if the FCC may hold a trampoline
101107
in which case the ``void zend_release_fcall_info_cache(zend_fcall_info_cache *fcc)`` should be used to release it.
102108
Moreover, if a reference to the closure is kept, this must be called *prior* to freeing the closure,

0 commit comments

Comments
 (0)