Guest User

class_alias

a guest
Jun 9th, 2010
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 1.15 KB | None | 0 0
  1. namespace tf\users {}
  2.  
  3. namespace tf\core {
  4.    
  5.     class collection {
  6.         private $_cl;
  7.         function __construct()  { $this->_cl = get_class($this);  }        
  8.         function get_cl()       { return $this->_cl; }
  9.     }
  10.    
  11.     class core {
  12.    
  13.         private $_cl;
  14.         function register($name) {
  15.        
  16.             $from = 'tf\\core\\collection';
  17.             $to =   'tf\\users\\' . $name;
  18.            
  19.             printf ("aliasing %s --> %s : %s <br/> \n",  $from, $to, class_alias($from, $to)?'OK':'FAIl');
  20.            
  21.             $a = new $to ();
  22.             $this->_cl = get_class($a);
  23.             return $a;
  24.         }
  25.         function get_cl()       { return $this->_cl; }
  26.     }
  27.    
  28. }
  29.  
  30.  
  31. namespace {
  32.     use tf\core\core;
  33.     $core = new core();
  34.     $test = $core->register('test');
  35.     printf("core: %s, result: %s, get_class: %s <br/>\n", $core->get_cl(), $test->get_cl(), get_class($test));
  36. }
  37.  
  38. /*
  39. результат:
  40. aliasing tf\core\collection --> tf\users\test : OK
  41. core: tf\core\collection, result: tf\core\collection, get_class: tf\core\collection
  42.  
  43. ожидал получить:
  44.  tf\users\test
  45. */
Advertisement
Add Comment
Please, Sign In to add comment