PHP method_exists 不适用于类(class) child ?

标签 php

class parent{
   function run($methodname) {
      echo method_exists(__CLASS__, $methodname);      
   }
}

class child extends parent {
   function order(){
      echo 'hello';
   }
}

$test = new child();
$test->run('order'); //false

method_exists 找不到子类中的方法顺序。

如何让它发挥作用?

最佳答案

__CLASS__ 绑定(bind)到它所使用的类,而不是继承类。您可以通过使用 $this 作为对象引用来解决这个问题。

另见 http://www.php.net/manual/en/language.oop5.late-static-bindings.php .

关于PHP method_exists 不适用于类(class) child ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5700197/

相关文章:

PHP和jQuery实时消息系统多重问题

php - Laravel 干预/图像调整大小返回 null。拉维尔 5

php - MySQLi/PHP - 从一个数据库中提取数据。插入到另一个数据库

javascript - JQuery 抖动对错误的影响

javascript - 来自数据库的值没有出现在 php 中

php - 在Mysql表中保存座位安排

php - 使用 ajax PHP 在每个下拉列表中动态填充下拉列表

php - 使用 GROUP BY 和 ORDER BY 条件在两个 MySQL 表上加入与联合

php - 消息:未定义的属性:使用 codeigniter 的 CI_Loader::$session

php - 为什么会出现这些php session_start()错误?