有2个文件:
1、index.php
2、index.controller.php
在index.php 里面声明了一个变量 $method;
在index.php 里面 include 了 index.controller.php.
请问在index.controller.php 里面 class index_controller类里面的方法 如何使用$method
我是判断该方法在不在。
index.php Code:
$method = show;
index.controller.php Code: class index_controller {
 function __construct()
 {
    if(!method_exists($this,$method)){
exit("不存在的方法");
    } 
 }
}

解决方案 »

  1.   

    构造函数中获取不到$method的值,申明global 或者传递进去。
      

  2.   

    class index_controller {
     function __construct($method)
     {
        if(!method_exists($this,$method)){
        exit("不存在的方法");
        } 
     }
    }index.php 
    include 'index.controller.php';
    $method = 'show';
    $index=new index_controller($method);