在php中使用命名空间动态初始化类

时间:2015-11-28 16:42:35

标签: php namespaces

我是新手在php中命名空间,我试图使用名称空间动态启动类,但它说找不到类。

我的文件夹结构为 -helper / automationhelper.php -pageobject / test.php的

Automationhelper.php

namespace helper;
use helper\ExcelHelper;


class UIAutomationHelper {

// UI Automation Initiator.
public function initiator() {
    $excelhelper = new ExcelHelper();
    $testdata = $excelhelper->readTestData (); //here reading test.xls so the screen name[0] = test;
    $screen_name = array_keys ( $testdata );
    if (isset ( $screen_name [0] )) {  
        $pageObjectname = CommonHelper::replace_string ( '_', "", $screen_name [0] );
        $pageInstance = new $pageObjectname; //here throws exception class not found.
        $dependency_flag = false;
                            // $excelhelper->writeTestCaseResponse($response, $workbook, $sheetname, $rows);
                        } else {
                            // error_log(var_export("method not found->".$method));
                        }
    }
}

test.php的: -

 use helper\PortalHelper as PortalHelper;

 class test {
   private $portalHelperObj;
    public function __construct() {
         $this->portalHelperObj = PortalHelper::getClassInstance ();
    }
}

0 个答案:

没有答案