rfc:fallback-to-root-scope-deprecation
Differences
This shows you the differences between two versions of the page.
Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
rfc:fallback-to-root-scope-deprecation [2018/02/03 08:00] – wesnetmo | rfc:fallback-to-root-scope-deprecation [2018/02/03 16:26] (current) – wesnetmo | ||
---|---|---|---|
Line 9: | Line 9: | ||
===== Introduction ===== | ===== Introduction ===== | ||
- | Fallback to global scope allow namespaces to access in an unqualified manner symbols actually residing in the root namespace. | + | Fallback to global scope allows |
<code php> | <code php> | ||
Line 22: | Line 22: | ||
===== Proposal ===== | ===== Proposal ===== | ||
- | This RFC proposes to deprecate the fallback to root scope, by emitting a '' | + | This RFC proposes to deprecate the fallback to root scope, by emitting a deprecation notice, e.g.: |
< | < | ||
Line 29: | Line 29: | ||
</ | </ | ||
- | It also proposes, considered the entity of the change, that the " | + | It also proposes, considered the entity of the change, that the " |
In fact, if the feature is removed and autoloading of functions and constants is introduced at the same time, authors that failed to update their code can easily shim it using just few lines of code: | In fact, if the feature is removed and autoloading of functions and constants is introduced at the same time, authors that failed to update their code can easily shim it using just few lines of code: | ||
Line 35: | Line 35: | ||
<code php> | <code php> | ||
// Fallback to global scope shim | // Fallback to global scope shim | ||
- | // This code simply | + | // This code simply |
- | register_autoloader( | + | // Note: this is just a non-binding PoC |
- | | + | autoload_register(AUTOLOAD_FUNCTION | AUTOLOAD_CONST, |
- | | + | // Assumes $namespaced is NOT prepended with \ |
- | + | // Assumes | |
- | $start = strrpos($QN, " | + | |
- | if($start === false){ return; } | + | // Find last occurrence of \ |
- | + | $offset | |
- | // e.g. " | + | |
- | $sourceNS | + | // Return if none; this is only active for namespaced symbols |
- | + | | |
- | // e.g. " | + | |
- | | + | // Fallback symbol' |
- | + | $fallback | |
- | | + | |
- | | + | // Alias the function |
- | | + | if($type & \AUTOLOAD_FUNCTION && |
- | | + | \function_alias($fallback, |
- | | + | |
- | namespace ' . $sourceNS . '; | + | |
- | function ' . $rootSymbol . ' | + | |
- | return | + | |
- | } | + | |
- | '); | + | |
- | }elseif( | + | |
- | ($type & AUTOLOAD_CONST) && | + | |
- | defined($rootSymbol) | + | |
- | ){ | + | |
- | eval(' | + | |
- | namespace ' . $sourceNS . '; | + | |
- | const ' . $rootSymbol . ' = \\' . $rootSymbol . '; | + | |
- | '); | + | |
- | } | + | |
} | } | ||
- | ); | + | |
+ | // Alias the constant | ||
+ | if($type & \AUTOLOAD_CONST && \defined($fallback /*, false [1] */)){ | ||
+ | \define($namespaced, | ||
+ | } | ||
+ | }); | ||
+ | |||
+ | // [1] = may not trigger autoloading from an autoloader | ||
</ | </ | ||
- | If this RFC passes, authors | + | However, if this RFC passes, authors |
+ | |||
+ | ===== Migration Tools ===== | ||
+ | |||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * [[https:// | ||
+ | * More coming soon... | ||
===== Backward Incompatible Changes ===== | ===== Backward Incompatible Changes ===== | ||
Line 88: | Line 87: | ||
===== References ===== | ===== References ===== | ||
- | @TODO link discussion | + | - [[https:// |
rfc/fallback-to-root-scope-deprecation.1517644804.txt.gz · Last modified: 2018/02/03 08:00 by wesnetmo