-
Notifications
You must be signed in to change notification settings - Fork 3
Callbacks
* [#What_are_callbacks What are callbacks] * [#Java_Script_callbacks JavaScript callbacks] * [#PHP_callbacks PHP callbacks] * [#Param_Structures ParamStructures] * [#Supported_Methods Supported Methods] * [#Scope_Pseudo_Inheritance Scope Pseudo-Inheritance]
Callbacks are functions _called back_ by other functions in proper moment (eg on Ajax request error).
In JavaScript this pattern can be very flexible due to Closures support, which can be inline (no code break) and inherits scope (no need to passing params).
PHP has only simple support for callbacks so the case is more complicated. That's why [#Param_Structures] has been introduced in phpQuery.
Param Structures are lists of params. Such list can contain values defined by programmer or special places (CallbackParam objects) where function triggering callback will fill it's own values.
Example above shows how to easily pass custom params to callback using [#Param_Structures].
* `phpQuery::each()` * `phpQuery::map()` * `pq()->each()` * `pq()->map()`
There is easy way to pseudo-inherit scope in PHP. Scope means _variables accessible in specified point of code_. It's achieved using compact() and extract() functions.
Look at this modified [#Example_1]. Previous comments were removed.
In the future this functionality will be developed and more methods will support it.