rfc:alternative_callback_syntax
no way to compare when less than two revisions
Differences
This shows you the differences between two versions of the page.
Previous revisionLast revision | |||
— | rfc:alternative_callback_syntax [2017/09/22 13:28] – external edit 127.0.0.1 | ||
---|---|---|---|
Line 1: | Line 1: | ||
+ | ====== Request for Comments: Alternative syntax for creating fully resolved callbacks ====== | ||
+ | * Version: 1.0 | ||
+ | * Date: 2012-09-18 | ||
+ | * Author: Stephen Clay < | ||
+ | * Status: Under Discussion | ||
+ | * First Published at: https:// | ||
+ | ===== Introduction ===== | ||
+ | |||
+ | This RFC proposes the syntax '' | ||
+ | |||
+ | ===== Why? ===== | ||
+ | |||
+ | The string and array formats for callbacks present difficulties for users and IDEs: | ||
+ | |||
+ | * Most IDEs do not recognize callbacks, and so cannot offer autocompletion, | ||
+ | * Authors can misspell identifiers inside strings. | ||
+ | * Within namespaced code, authors can forget to prepend the namespace, since function calls within the namespace do not require it. | ||
+ | * Where use statements change the identifier for a class, authors can forget to specify the fully resolved name. | ||
+ | |||
+ | ===== Proposal ===== | ||
+ | |||
+ | PHP would provide a syntax, similar to a function call, which evaluates to a string or array callback value. This would be composed of the usual function call syntax, but replacing the parameter list and surrounding parenthesis with '':: | ||
+ | |||
+ | Under the proposal, the following expressions (within a namespace '' | ||
+ | |||
+ | <code php> | ||
+ | func:: | ||
+ | \func:: | ||
+ | CN:: | ||
+ | \CN:: | ||
+ | self:: | ||
+ | $obj-> | ||
+ | parent:: | ||
+ | </ | ||
+ | |||
+ | ==== Example Code ==== | ||
+ | |||
+ | <code php> | ||
+ | namespace NS1; | ||
+ | use NS2\Bee as B; | ||
+ | |||
+ | class A { | ||
+ | static function init() { | ||
+ | $inst = new self; | ||
+ | var_export($inst-> | ||
+ | $inst-> | ||
+ | } | ||
+ | function bar() { | ||
+ | var_export(B:: | ||
+ | } | ||
+ | } | ||
+ | |||
+ | function c() {} | ||
+ | |||
+ | var_export(var_export :: | ||
+ | var_export(A:: | ||
+ | A::init(); | ||
+ | var_export(c :: | ||
+ | </ | ||
+ | |||
+ | At runtime, these values would be passed to '' | ||
+ | |||
+ | <code php> | ||
+ | ' | ||
+ | ' | ||
+ | [$inst, ' | ||
+ | ' | ||
+ | ' | ||
+ | </ | ||
+ | |||
+ | ===== Considerations ===== | ||
+ | |||
+ | As '' | ||
+ | |||
+ | Any other use of '':: | ||
+ | |||
+ | As it is permitted between a function name and its argument list, for consistency and flexibility, | ||
+ | |||
+ | ===== Summary ===== | ||
+ | |||
+ | '':: | ||
+ | |||
+ | ===== Changelog ===== | ||
+ | |||
+ | * 2012-09-18 Created by Steve Clay |
rfc/alternative_callback_syntax.txt · Last modified: 2023/04/08 01:27 by mrclay