Advertisement
Timkor

polymorphicError

Aug 26th, 2020
1,360
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.59 KB | None | 0 0
  1. <?php
  2.     namespace test;
  3.     abstract class A
  4.     {
  5.         //public function foo()
  6.         protected function foo()
  7.         {
  8.             echo 'AA';
  9.         }
  10.     }
  11.  
  12.     class B extends A
  13.     {
  14.         public function foo()
  15.         {
  16.             echo 'BB';
  17.         }
  18.     }
  19.  
  20.     function bar(A $x)
  21.     {
  22.         $x->foo();
  23.     }
  24.  
  25. $b = new B;
  26.     bar($b);// BB expected, but if "foo" access modifier change to protected in parent class then
  27.             // PhpStorm suppose an error(underlined with a red wavy line),
  28.             // but, naturally,  runtime error will not occurred
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement