draxu26480 2018-04-19 10:44
浏览 82
已采纳

使用名称空间与现有代码的项目

I am trying to integrate PHPML with an existing project. PHPML uses namespaces and I have little experience using them.

I am able to run PHPML directly through my controller however when integrating it in to a class method I get the following error

Parse error: syntax error, unexpected 'use' (T_USE) in... on line 4

My class method:

class learn{
  public function return_adjustments(){
    include 'application/vendor/autoload.php';
    use Phpml\Regression\LeastSquares;
    use Phpml\Exception\FileException;

    $samples = $this->csv_to_array('samples.csv');
    $targets = $this->csv_to_array('targets.csv');

    $regression = new LeastSquares();
    $regression->train($samples, $targets);
}

Is it possible to do this correctly? I'm struggling on the concept of namespaces.

  • 写回答

1条回答 默认 最新

  • doushangxianq07480 2018-04-19 10:52
    关注

    Put the "use" statements at the very top of your file in order to import them properly.

    include 'application/vendor/autoload.php';
    
    class learn{
      public function return_adjustments() {
    
        $samples = $this->csv_to_array('samples.csv');
        $targets = $this->csv_to_array('targets.csv');
    
        $regression = new Phpml\Regression\LeastSquares();
        $regression->train($samples, $targets);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 QQ邮箱过期怎么恢复?
  • ¥15 登录他人的vue项目显示服务器错误
  • ¥15 (标签-android|关键词-app)
  • ¥60 如何批量获取json的url
  • ¥15 comsol仿真压阻传感器
  • ¥15 Python线性规划函数optimize.linprog求解为整数
  • ¥15 llama3中文版微调
  • ¥15 pg数据库导入数据序列重复
  • ¥15 三分类机器学习模型可视化分析
  • ¥15 本地测试网站127.0.0.1 已拒绝连接,如何解决?(标签-ubuntu)