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 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100
  • ¥15 关于#hadoop#的问题
  • ¥15 (标签-Python|关键词-socket)
  • ¥15 keil里为什么main.c定义的函数在it.c调用不了