douhan1860 2014-01-13 14:38
浏览 242
已采纳

PHP致命错误:PHP 5.5中找不到类'Curl'

I'm trying to run this code:

<?php 

    $url = 'https://api.stackexchange.com/2.1/comments';
    $data = array("site" => 'graphicdesign', "key" => "W*i*e*V*M*N*F*y*b*t*R*((", "filter" => "!2.5sIHWRkCVWC)rFPY_1P", "order" => "desc", "sort" => "creation");

    $httpresponse = (new Curl)->exec($url . '?' . http_build_query($data), [CURLOPT_ENCODING => 'gzip']); //Line 6

    $obj = json_decode($httpresponse);
    $response = $obj->{'items'};

However, it fails with this error:

$ php getcomments.php 
PHP Fatal error:  Class 'Curl' not found in /home/me/gdcommentgetter/getcomments.php on line 6

From my previous question, I though it might be a problem with my PHP version - class member access on instantiation ((new Object)->method()) wasn't available until PHP 5.4.

php --version, though, shows that I'm on a version > 5.4:

$ php --version
PHP 5.5.7-1+sury.org~precise+1 (cli) (built: Dec 12 2013 21:48:51) 
Copyright (c) 1997-2013 The PHP Group
Zend Engine v2.5.0, Copyright (c) 1998-2013 Zend Technologies
    with Zend OPcache v7.0.3-dev, Copyright (c) 1999-2013, by Zend Technologies

I've run sudo apt-get install php5-curl, as suggested many places, but it still fails with the same error. What's wrong?

  • 写回答

3条回答 默认 最新

  • dsh8009271 2014-01-13 14:41
    关注

    According to the documentation there is no class Curl.

    Perhaps you forgot to import some class of your own, or of another third-party vendor?

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 做个有关计算的小程序
  • ¥15 MPI读取tif文件无法正常给各进程分配路径
  • ¥15 如何用MATLAB实现以下三个公式(有相互嵌套)
  • ¥30 关于#算法#的问题:运用EViews第九版本进行一系列计量经济学的时间数列数据回归分析预测问题 求各位帮我解答一下
  • ¥15 setInterval 页面闪烁,怎么解决
  • ¥15 如何让企业微信机器人实现消息汇总整合
  • ¥50 关于#ui#的问题:做yolov8的ui界面出现的问题
  • ¥15 如何用Python爬取各高校教师公开的教育和工作经历
  • ¥15 TLE9879QXA40 电机驱动
  • ¥20 对于工程问题的非线性数学模型进行线性化