Advertisement
arxeiss

PHP Self vs Static

Jan 28th, 2019
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.47 KB | None | 0 0
  1. <?php
  2.  
  3. class Foo
  4. {
  5.     const XXX_CONST = "abc";
  6.  
  7.     public static function printSelfOut()
  8.     {
  9.         var_dump(self::XXX_CONST);
  10.     }
  11.  
  12.     public static function printStaticOut()
  13.     {
  14.         var_dump(static::XXX_CONST);
  15.     }
  16. }
  17.  
  18. class Bar extends Foo
  19. {
  20.     const XXX_CONST = "123";
  21. }
  22.  
  23. Foo::printSelfOut();    // Print out: abc
  24. Foo::printStaticOut();  // Print out: abc
  25. Bar::printSelfOut();    // Print out: abc
  26. Bar::printStaticOut();  // Print out: 123
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement