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);
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 对于相关问题的求解与代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 信号傅里叶变换在matlab上遇到的小问题请求帮助
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作
  • ¥15 求NPF226060磁芯的详细资料