rfc:autofunc

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
Next revisionBoth sides next revision
rfc:autofunc [2011/08/05 00:35] – future tyraelrfc:autofunc [2011/08/06 11:16] – under discussion tyrael
Line 3: Line 3:
   * Date: 2011-08-05   * Date: 2011-08-05
   * Author: Ferenc Kovacs <tyra3l@gmail.com>   * Author: Ferenc Kovacs <tyra3l@gmail.com>
-  * Status: Draft+  * Status: Under Discussion
   * First Published at: https://wiki.php.net/rfc/autofunc   * First Published at: https://wiki.php.net/rfc/autofunc
  
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 a potential implementation which would be consistent with what we have for autoloading classes. +The topic of supporting function autoloading was brought up many times in the past, this RFC introduces a potential implementation which would be consistent with what we have for autoloading classes. 
  
 ===== Proposal ===== ===== Proposal =====
  
-The suggested change would be pretty straigtforward and BC compatible: +The suggested change would be pretty straightforward and BC compatible: 
-  * 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 of T_CLASS and T_FUNCTION for now. +  * 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 combination of T_CLASS and T_FUNCTION for now. 
-    * as you would guess, this would work the same way as the $error_types parameter works for set_error_handler: you can specify for which type(s) of missing tokens should be the autoloader called. +    * As you would guess, this would work the same way as the $error_types parameter works for set_error_handler: you can specify for which type(s) of missing tokens the autoloader should be called. 
-  * the type for the missing token should be also passed to the $autoload_function callback as a second param. +  * The type for the missing token should also be passed to the $autoload_function callback as a second param. 
-    * this is needed to be able to handle multiple types of tokens with a common callback. +    * This is needed to be able to handle multiple types of tokens with a common callback. 
-    * Note that passing more parameter to a function than it has in it'definition is valid, this would be also backward compatible change. +    * Note that passing more parameters to a function than it has in its definition is valid, this would also be a backward compatible change. 
-  * change the current class autoloading to only call the autoloaders which match with the T_CLASS types. +  * Change the current class autoloading to only call the autoloaders which match with the T_CLASS types. 
-  * add the function autoloading to only call the autoloaders which match with the T_FUNCTION types.+  * Add the function autoloading to only call the autoloaders which match with the T_FUNCTION types.
  
 ==== 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 (T_DECLARE, T_CONST, etc.) with this interface. 
 + 
 +==== Examples ==== 
 +<code php> 
 + <?php 
 + // old behavior 
 + spl_autoload_register( 
 +  function ($name) { 
 +   // include the class definition 
 +   /* ... */ 
 +  } 
 + ); 
 + 
 + // autoload functions 
 + spl_autoload_register( 
 +  function ($name) { 
 +   // include the function definition 
 +   /* ... */ 
 +  }, 
 +  true, 
 +  false, 
 +  T_FUNCTION 
 + ); 
 + 
 + // autoload mixed 
 + spl_autoload_register( 
 +  function ($name, $type) { 
 +   switch($type){ 
 +    case T_CLASS: 
 +     /* ... */ 
 +     break; 
 +    case T_FUNCTION: 
 +     /* ... */ 
 +     break;       
 +   } 
 +  }, 
 +  true, 
 +  false, 
 +  T_CLASS|T_FUNCTION 
 + ); 
 +</code> 
  
 ==== Patch ==== ==== Patch ====
rfc/autofunc.txt · Last modified: 2017/09/22 13:28 by 127.0.0.1