【问题标题】:What's the appropriate way of passing arguments to the static class method when it's made callable?当静态类方法可调用时,将参数传递给静态类方法的适当方法是什么?
【发布时间】:2018-05-09 17:07:44
【问题描述】:

我试过下面的代码:

<?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");
?>

输出:

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

为什么我会收到此警告?我想删除它。所以,请指导我。

【问题讨论】:

    标签: php function callback static-methods callable


    【解决方案1】:

    在 PHP 中重写方法时,重写方法签名应该与父相同方法兼容!这意味着你应该在扩展类中声明一个public static function who($simba)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-04-23
      • 1970-01-01
      • 1970-01-01
      • 2015-11-13
      • 2019-08-11
      • 2012-10-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多