0

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?

4
  • 1
    Curl isn't a class, it's a library. Also, remove credentials from your post asap Commented Jan 13, 2014 at 14:40
  • Did you restart Apache after installing php-curl? Commented Jan 13, 2014 at 14:42
  • @AlmaDo There aren't any credentials in it. The filter isn't secret and the key has been censored (it isn't terribly secret either). Commented Jan 13, 2014 at 14:43
  • @JamesAnderson I have, and I'm running it from the command line anyway. Commented Jan 13, 2014 at 14:44

3 Answers 3

7

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?

Sign up to request clarification or add additional context in comments.

Comments

2

You are probably using some third-party Curl library which provides the class.

Otherwise you need to use curl_init() and if you haven't got curl installed you need to install like so:

sudo apt-get install php5-curl

this is for Ubuntu machines only and some other distros probably

Comments

0

Well there is no built it curl class in php but many devs have created their own wrapper around curl like https://github.com/sirfilip/curl/blob/master/Curl.php . The reason that it works on your server is because maybe you have installed some php lib on the server that you dont have it installed locally.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.