rfc:autofunc
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:autofunc [2011/08/05 00:35] – future tyrael | rfc:autofunc [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 3: | Line 3: | ||
* Date: 2011-08-05 | * Date: 2011-08-05 | ||
* Author: Ferenc Kovacs < | * Author: Ferenc Kovacs < | ||
- | * Status: | + | * Status: |
* First Published at: https:// | * First Published at: https:// | ||
Line 9: | Line 9: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | The topic of supporting function autoloading was brought up many times in the past, this RFC tries to introduce | + | The topic of supporting function autoloading was brought up many times in the past, this RFC introduces |
===== Proposal ===== | ===== Proposal ===== | ||
- | The suggested change would be pretty | + | The suggested change would be pretty |
- | * add a fourth optional parameter for spl_autoload_register called $types with the default value of T_CLASS(this would keep the BC), supported values would be any compination | + | * Add two new constants to spl: SPL_AUTOLOAD_CLASS, |
- | * as you would guess, this would work the same way as the $error_types parameter works for set_error_handler: | + | * Add a fourth optional parameter for spl_autoload_register called $types with the default value of SPL_AUTOLOAD_CLASS |
- | * the type for the missing token should be also passed to the $autoload_function callback as a second param. | + | * As you would guess, this would work the same way as the $error_types parameter works for set_error_handler: |
- | * this is needed to be able to handle multiple types of tokens with a common callback. | + | * The type for the missing token should |
- | * Note that passing more parameter | + | * This is needed to be able to handle multiple types of tokens with a common callback. |
- | * change | + | * Note that passing more parameters |
- | * add the function autoloading to only call the autoloaders which match with the T_FUNCTION | + | * Change |
+ | * Add the function autoloading to only call the autoloaders which match with the SPL_AUTOLOAD_FUNCTION | ||
==== Future improvements ==== | ==== Future improvements ==== | ||
- | Notice that currently only functions are proposed, but we could implement autoloading other tokens(T_CONST?) with this interface. | + | Notice that currently only functions are proposed, but we could implement autoloading other tokens (SPL_AUTOLOAD_CONSTANT, |
+ | |||
+ | ==== Examples ==== | ||
+ | <code php> | ||
+ | <? | ||
+ | // old behavior | ||
+ | | ||
+ | function ($name) { | ||
+ | // include the class definition | ||
+ | /* ... */ | ||
+ | } | ||
+ | ); | ||
+ | |||
+ | // autoload functions | ||
+ | | ||
+ | function ($name) { | ||
+ | // include the function definition | ||
+ | /* ... */ | ||
+ | }, | ||
+ | true, | ||
+ | false, | ||
+ | SPL_AUTOLOAD_FUNCTION | ||
+ | ); | ||
+ | |||
+ | // autoload mixed | ||
+ | | ||
+ | function ($name, $type) { | ||
+ | | ||
+ | case SPL_AUTOLOAD_CLASS: | ||
+ | /* ... */ | ||
+ | | ||
+ | case SPL_AUTOLOAD_FUNCTION: | ||
+ | /* ... */ | ||
+ | | ||
+ | } | ||
+ | }, | ||
+ | true, | ||
+ | false, | ||
+ | SPL_AUTOLOAD_CLASS|SPL_AUTOLOAD_FUNCTION | ||
+ | ); | ||
+ | </ | ||
==== Patch ==== | ==== Patch ==== | ||
Line 39: | Line 81: | ||
* [[http:// | * [[http:// | ||
+ | ==== Changelog ==== | ||
+ | * 2011.08.17 - replace the T_* constants with SPL_AUTOLOAD_* | ||
rfc/autofunc.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1