无法'使用'特质

时间:2017-08-18 22:55:05

标签: php

我第一次尝试使用特征。只有我无法 [INFO] Building rap-web Maven Webapp 0.0.1-SNAPSHOT [INFO] ------------------------------------------------------------------------ [INFO] **[INFO] --- jaxb2-maven-plugin:1.6:xjc (xjc) @ rap-web --- [INFO] Generating source... [WARNING] No encoding specified; default platform encoding will be used for generated sources. [INFO] parsing a schema... [INFO] compiling a schema... [INFO] [INFO] --- maven-resources-plugin:2.6:resources (default-resources) @ rap-web --- [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] Copying 15 resources [INFO] Copying 3 resources to wsdl [INFO] Copying 1 resource to config [INFO] [INFO] --- maven-compiler-plugin:2.5.1:compile (default-compile) @ rap-web --- [WARNING] File encoding has not been set, using platform encoding Cp1252, i.e. build is platform dependent! [INFO] Compiling 50 source files to C:\Users\xx67047\DSA-GIT-Projects\10.22.17-dsa-rap-services\rap-web\target\classes** [INFO] [INFO] --- maven-resources-plugin:2.6:testResources (default-testResources) @ rap-web --- [WARNING] Using platform encoding (Cp1252 actually) to copy filtered resources, i.e. build is platform dependent! [INFO] skip non existing resourceDirectory C:\Users\xx67047\DSA-GIT-Projects\10.22.17-dsa-rap-services\rap-web\src\test\resources [INFO] [INFO] --- maven-compiler-plugin:2.5.1:testCompile (default-testCompile) @ rap-web --- [INFO] Nothing to compile - all classes are up to date [INFO] [INFO] --- maven-surefire-plugin:2.12.4:test (default-test) @ rap-web --- 他们。当包含特征存在的文件时使用特征会导致以下错误:

  

解析错误:语法错误,意外“使用”(T_USE)   第38行的C:\ xampp \ htdocs \ hyper \ Class_HyperHeuristic.php

我正在使用一种略微花哨的方式来要求文件和使用特征:

use

虽然只是手动要求它们会导致相同的错误;问题不在于循环。

在循环中执行以下命令:

 private function require_and_use_traits($number_of_heuristics){
     for($t=1; $t<=$number_of_heuristics; $t++ ){
        require_once __BASEPATH__ . DIRECTORY_SEPARATOR . 'heuristic' . $t . '.php';
        use heurisitc . $t;
     }
 }

显示完全有效的路径。

我正在使用支持特征的PHP 5.6.30。任何人都可以建议问题是什么?

1 个答案:

答案 0 :(得分:1)

在方法之外,你需要use类中的Trait,比如参数定义。

我建议你阅读traits documentation(感谢@axiac链接)