rfc:function_autoloading
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:function_autoloading [2015/09/03 04:51] – Add streams ircmaxell | rfc:function_autoloading [2017/09/22 13:28] (current) – external edit 127.0.0.1 | ||
---|---|---|---|
Line 11: | Line 11: | ||
PHP presently offers the ability to import class-like structures (classes, interfaces and traits) via a callback (or series of them) that can be registered. This lets a developer " | PHP presently offers the ability to import class-like structures (classes, interfaces and traits) via a callback (or series of them) that can be registered. This lets a developer " | ||
- | Presently, other types of symbols tables are not autoloadable. This RFC proposes a new unified autoloading mechanism to unify autoloading efforts across all three symbol tables (class, function, stream wrapper and constant). | + | Presently, other types of symbols tables are not autoloadable. This RFC proposes a new unified autoloading mechanism to unify autoloading efforts across all four symbol tables (class, function, stream wrapper and constant). |
===== Proposal ===== | ===== Proposal ===== | ||
Line 23: | Line 23: | ||
* // | * // | ||
* // | * // | ||
- | * // | + | * // |
- | * // | + | * // |
==== Userland Functions ==== | ==== Userland Functions ==== | ||
Line 32: | Line 32: | ||
=== bool php\autoload_register(callable $callback, int $type, bool $prepend = false) === | === bool php\autoload_register(callable $callback, int $type, bool $prepend = false) === | ||
- | This function behaves similar to the current // | + | This function behaves similar to the current // |
=== bool php\autoload_unregister(callable $callback, int $type = 0) === | === bool php\autoload_unregister(callable $callback, int $type = 0) === | ||
Line 63: | Line 63: | ||
zend_fcall_info_cache fcc; | zend_fcall_info_cache fcc; | ||
zval *callable; | zval *callable; | ||
+ | int pass_type; | ||
} _zend_autoload_func; | } _zend_autoload_func; | ||
</ | </ | ||
Line 118: | Line 119: | ||
}, php\AUTOLOAD_FUNCTION); | }, php\AUTOLOAD_FUNCTION); | ||
foo(); // string(3) " | foo(); // string(3) " | ||
+ | new foo(); // FATAL_ERROR as no autoloader is registered | ||
+ | ?> | ||
+ | </ | ||
+ | |||
+ | === Multiple Type Behavior === | ||
+ | |||
+ | By passing a bitwise-or' | ||
+ | |||
+ | <file php multiple_type.php> | ||
+ | <?php | ||
+ | php\autoload_register(function($name, | ||
+ | var_dump($name, | ||
+ | switch ($type) { | ||
+ | case php\AUTOLOAD_FUNCTION: | ||
+ | | ||
+ | | ||
+ | case php\AUTOLOAD_CONSTANT: | ||
+ | | ||
+ | | ||
+ | } | ||
+ | }, php\AUTOLOAD_FUNCTION | php\AUTOLOAD_CONSTANT); | ||
+ | foo(); // string(3) " | ||
+ | FOO; // string(3) " | ||
new foo(); // FATAL_ERROR as no autoloader is registered | new foo(); // FATAL_ERROR as no autoloader is registered | ||
?> | ?> | ||
Line 126: | Line 150: | ||
<file php multiple_registration.php> | <file php multiple_registration.php> | ||
<?php | <?php | ||
- | $callback = function($name) { | + | $callback = function($name, $type) { |
var_dump($name); | var_dump($name); | ||
if ($name === ' | if ($name === ' | ||
Line 147: | Line 171: | ||
This RFC proposes to strip the current // | This RFC proposes to strip the current // | ||
- | This means that calls to // | + | This means that calls to // |
=== __autoload() === | === __autoload() === |
rfc/function_autoloading.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1