2014-06-09 15 views
2

我有如PHP类:以纯文本形式生成某些PHP类的所有公共函数?

class test { 
    public function newTest(){ 
      $this->bigTest(); 
      $this->smallTest(); 
    } 

    private function bigTest(){ 
      //Big Test Here 
    } 

    private function smallTest(){ 
      //Small Test Here 
    } 

    public function scoreTest(){ 
      //Scoring code here; 
    } 
} 

现在,有越来越级测试的功能,如下面的纯文本文件如像test_functions.txt或任何

test/newTest 
test/bigTest 
test/smallTest 
test/scoreTest 

回答

2
的任何possiblility

您可以使用get_class_methods做到这一点:

<?php 
class test { 
    public function newTest(){ 
     $this->bigTest(); 
     $this->smallTest(); 
    } 

    private function bigTest(){ 
     //Big Test Here 
    } 

    private function smallTest(){ 
     //Small Test Here 
    } 

    public function scoreTest(){ 
     //Scoring code here; 
    } 

    public function showMe(){ 
     echo 'Class Name: test - inside object'; 
     $class_methods = get_class_methods($this); 
     print_r($class_methods); 
    } 
} 

    $class_methods = get_class_methods('test'); 
    echo 'Class Name: test - outside object'; 
    print_r($class_methods); 

    $test=new test(); 
    $test->showMe(); 

?> 

然而,这将只能访问公共职能,如果从出局称为认识对象。但是,您可以在对象本身内完美地调用它。

输出:

Class Name: test - outside objectArray 
(
    [0] => newTest 
    [1] => scoreTest 
    [2] => showMe 
) 
Class Name: test - inside objectArray 
(
    [0] => newTest 
    [1] => bigTest 
    [2] => smallTest 
    [3] => scoreTest 
    [4] => showMe 
) 
+0

感谢的人。我正在计划生成所有在不同文件夹中存在的类丢失的公共功能,比如使用一个php创建100个类。文件夹结构:test/controller/test.php。 – user3145348

相关问题