Use of undefined constant CURLOPT_POST - assumed 'CURLOPT_POST'
Asked Answered
C

2

17

I am making a cURL request via Kohana 3.2 but I get the following error when it tries to access CURLOPT_POST constant:

Use of undefined constant CURLOPT_POST - assumed 'CURLOPT_POST'

From Kohana 3.2 system/classes/kohana/request/client/curl.php

public function _set_curl_request_method(Request $request, array $options)
{
    switch ($request->method()) {
        case Request::POST:
            $options[CURLOPT_POST] = TRUE;
            break;
        case Request::PUT:
            $options[CURLOPT_PUT] = TRUE;
            break;
        default:
            $options[CURLOPT_CUSTOMREQUEST] = $request->method();
            break;
    }
    return $options;
}

My application code:

$request = Request::factory($uri);
$request->query('key', $key);
$request->post($params);
$request->method(Request::POST);

// fails here
$response = $request->execute();

I have tested that curl is active as an extension using:

if (in_array  ('curl', get_loaded_extensions()))
{
    echo '1';
}
else
{
    echo '0';
}

What is the problem here? I am using Windows 7, PHP 5.4.12, and Apache 2.4.

Careerist answered 28/3, 2014 at 13:0 Comment(12)
Can you show the piece of code where you're actually using CURLOPT_POST?Fellner
Added the code to my postCareerist
Do you already have an acutal call to any of the curl function in your script? One that would make php bail out with undefined function curl_.... if the curl extension isn't available? If not (or unsure) better double-check via phpinfo(), extension_loaded('curl'), ...Gromme
No, can you show the code where you making the actual request? The code you've posted is a snippet from the Kohana library. Are you making the request via the request factory? if so, how? show that part of the code.. e.g. $request = Request::factory($url)->method('POST')->post('key', 'value');Im
I know it's early and all, but isn't this expected behavior from an unquoted array key?Blower
@MattThompson This is how you set curl options (see manual)Fellner
@Matt : it's a constant defined by the curl extension, see docs.php.net/constantsGromme
@LatheesanKanes added application codeCareerist
but in this context it is being used as an array key for an array created by the kohana library... it is not being used directly to set the option. I understand how curl works.Blower
@MattThompson See my link, they use it as an unquoted key in the manual as wellFellner
@Matt : You are confusing string literals and constants, docs.php.net/manual/en/language.types.array says "Note: This does not mean to always quote the key. Do not quote keys which are constants or variables, as this will prevent PHP from interpreting them."Gromme
@Gromme - I understand that part, from looking at it, I was just confused as to whether this $options array was being passed directly as a parameter to curl or if it was an array of available curl settings within kohana. I hope that makes sense. I implicitly understand the difference between string keys and constants, I just misinterpreted the code posted I guess.Blower
C
5

I noticed extension=php_curl.dll was commented out in C:\wamp\bin\php\php5.4.12\php.ini but active via C:\wamp\bin\apache\Apache2.4.4\bin\php.ini.

I found that uncommenting the line in C:\wamp\bin\php\php5.4.12\php.ini fixed my issue.

Careerist answered 28/3, 2014 at 13:45 Comment(0)
S
19

First, let's check php-curl has been installed on your server by

aptitude search php-curl

or aptitude search php5.6-curl

if that hasn't been installed yet, let's install it by

sudo apt-get install php5.6-curl
Sanalda answered 8/2, 2017 at 1:50 Comment(1)
This will not work, as the question-asker specifically states that they have an older version of PHP (5.4.12), which would be incompatible with php5.6-curl. Please carefully read questions before providing answers. Also, this question was asked 2 years ago, and already had an accepted solution. Please try to avoid 'bumping' questions to the top by providing answers to them, unless the question was not already marked as resolved, or you found a dramatically better alternative approach to the problem :)Lollapalooza
C
5

I noticed extension=php_curl.dll was commented out in C:\wamp\bin\php\php5.4.12\php.ini but active via C:\wamp\bin\apache\Apache2.4.4\bin\php.ini.

I found that uncommenting the line in C:\wamp\bin\php\php5.4.12\php.ini fixed my issue.

Careerist answered 28/3, 2014 at 13:45 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.