Advertisement
Guest User

Untitled

a guest
Sep 25th, 2013
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.65 KB | None | 0 0
  1. class Foo {
  2.     public function getClassname() {
  3.         return get_called_class();
  4.     }
  5.     public function getSelf(){
  6.         return new class extends self { };
  7.     }
  8.     public function getStatic() {
  9.         return new class extends self { };
  10.     }
  11. }
  12.  
  13. class Bar extends Foo {
  14.    
  15. }
  16.  
  17. $foo = new Foo();
  18. echo $foo->getClassName();              // Foo
  19. echo $foo->getSelf()->getClassName();   // Foo::<class>
  20. echo $foo->getStatic()->getClassName(); // Foo::<class>
  21.  
  22. $bar = new Bar();
  23. echo $bar->getClassName();              // Bar
  24. echo $bar->getSelf()->getClassName();   // Foo::<class>
  25. echo $bar->getStatic()->getClassName(); // Bar::<class>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement