rfc:fallback-to-root-scope-deprecation

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revisionPrevious revision
Next revision
Previous revision
rfc:fallback-to-root-scope-deprecation [2018/02/03 10:31] wesnetmorfc:fallback-to-root-scope-deprecation [2018/02/03 16:26] (current) wesnetmo
Line 22: Line 22:
 ===== Proposal ===== ===== Proposal =====
  
-This RFC proposes to deprecate the fallback to root scope, by emitting a ''Notice'' (''E_DEPRECATED''), e.g.:+This RFC proposes to deprecate the fallback to root scope, by emitting a deprecation notice, e.g.:
  
 <code> <code>
Line 35: Line 35:
 <code php> <code php>
 // Fallback to global scope shim // Fallback to global scope shim
-// This code simply copies \strlen to \Current\NS\strlen +// This code simply aliases \strlen to \Current\NS\strlen 
-register_autoloader( +// Note: this is just a non-binding PoC 
-    AUTOLOAD_FUNCTION | AUTOLOAD_CONST, +autoload_register(AUTOLOAD_FUNCTION | AUTOLOAD_CONST, function(string $namespaced, int $type){ 
-    function(string $QN, int $type){ +    // Assumes $namespaced is NOT prepended with \ 
-         +    // Assumes $namespaced is NOT already loaded 
-        $start = strrpos($QN, "\\"); + 
-        if($start === false){ return; } +    // Find last occurrence of \ 
-         +    $offset \strrpos($namespaced, "\\"); 
-        // e.g. "My\Full\NS" + 
-        $sourceNS = substr($QN, 0, $start); +    // Return if none; this is only active for namespaced symbols 
-         +    if($offset === false){ return; } 
-        // e.g. "strlen" + 
-        $rootSymbol = substr($QN, $start + 1); +    // Fallback symbol's name: 
-         +    $fallback \substr($namespaced, $offset + 1); 
-        if+ 
-            ($type & AUTOLOAD_FUNCTION&& +    // Alias the function 
-            function_exists($rootSymbol) +    if($type & \AUTOLOAD_FUNCTION && \function_exists($fallback /*, false [1] */)){ 
-        ){ +        \function_alias($fallback, $namespaced); // May be introduced too, works like class_alias
-            eval(' +
-                namespace ' . $sourceNS . '; +
-                function ' . $rootSymbol . '(...$args){ +
-                    return \\' . $rootSymbol . '(...$args); +
-                } +
-            '); +
-        }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, \constant($fallback)); 
 +    } 
 +}); 
 + 
 +// [1] = may not trigger autoloading from an autoloader
 </code> </code>
  
rfc/fallback-to-root-scope-deprecation.1517653872.txt.gz · Last modified: 2018/02/03 10:31 by wesnetmo