daily pastebin goal
52%
SHARE
TWEET

Untitled

a guest Nov 8th, 2018 92 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Case 1
  2. ```
  3. <?php
  4. interface AI {
  5.     const FOO = 'a';
  6. }
  7.  
  8. class A implements AI {
  9.     const FOO = 'Class A';
  10. }
  11.  
  12. function test(AI $obj)
  13. {
  14.     echo $obj::FOO;
  15. }
  16.  
  17. $obj = new A();
  18. test($b);
  19. ```
  20.  
  21. Result:
  22. `Fatal error: Cannot inherit previously-inherited or override constant FOO from interface AI in [...][...] on line 6`
  23.  
  24. Case 2
  25. ```
  26. <?php
  27. interface AI {
  28.     const FOO = 'Interface';
  29. }
  30. class A implements AI {}
  31. class B extends A {
  32.     const FOO = 'Class B';
  33. }
  34.  
  35. function test(AI $var)
  36. {
  37.     echo $var::FOO;
  38. }
  39.  
  40. $obj = new B();
  41. test($obj);
  42. ```
  43. Result:
  44. `Class B`
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top