Advertisement
wzul

PHP Class Name Alias

Mar 5th, 2023
606
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.39 KB | None | 0 0
  1. <?php
  2. /**
  3.  * https://stackoverflow.com/questions/5861940/is-there-a-way-to-dynamically-change-the-name-of-the-class-being-autoloaded
  4.  */
  5.  
  6. class Gila_Baby {
  7.   public function __construct() {
  8.     echo 'hai';
  9.   }
  10. }
  11.  
  12. function autoload($class_name) {
  13.   $real_class_name = 'Gila_' . $class_name;
  14.   class_alias($real_class_name, $class_name);
  15. }
  16.  
  17. autoload('Baby');
  18.  
  19. new Baby(); // output: hai
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement