Search code examples
phpfunctioncallbackstatic-methodscallable

What's the appropriate way of passing arguments to the static class method when it's made callable?


I tried below code :

<?php
  class A {
    public static function who($simba) {
      echo "A\n";
      echo $simba;
    }
  }

  class B extends A {
    public static function who() {
      echo "B\n";
    }
  }
  call_user_func(array('B', 'parent::who'), $nangal="huip");
?>

Output :

Warning: Declaration of B::who() should be compatible with A::who($simba)
A huip

Why I'm getting this warning? I want to remove it. So, please guide me.


Solution

  • When overriding methods in PHP, The Overriding method signature should be compatible with parent same method! This means you should declare a public static function who($simba) in extended class!