Skip to content

Conversation

Copy link

Copilot AI commented Nov 5, 2025

When reusing a Curl object instance, CURLOPT_CUSTOMREQUEST set by PUT/PATCH/DELETE persisted across requests, causing subsequent GET/POST requests to use incorrect methods or carry over POST data.

Changes

  • get() method: Set CURLOPT_CUSTOMREQUEST to null (was "GET") and clear CURLOPT_POSTFIELDS
  • post() method: Set CURLOPT_CUSTOMREQUEST to null (was "POST")

Per cURL documentation, standard methods should use CURLOPT_HTTPGET/CURLOPT_POST, not CURLOPT_CUSTOMREQUEST. Setting to null clears previous custom methods.

Example

$curl = new Curl();

// PUT sets CURLOPT_CUSTOMREQUEST='PUT', CURLOPT_POST=true, CURLOPT_POSTFIELDS
$curl->put('http://api.example.com/users/123', ['name' => 'John'], true);

// GET now properly clears CURLOPT_CUSTOMREQUEST and CURLOPT_POSTFIELDS
$curl->get('http://api.example.com/users/123');  // ✓ Works correctly

Added SequentialRequestsTest.php covering GET/POST after PUT/PATCH/DELETE scenarios.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • https://api.github.com/repos/doctrine/instantiator/zipball/c6222283fa3f4ac679f8b9ced9a4e23f163e80d0
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/r8gnS3 /usr/bin/composer install (http block)
  • https://api.github.com/repos/nikic/PHP-Parser/zipball/3a454ca033b9e06b63282ce19562e892747449bb
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/r8gnS3 /usr/bin/composer install (http block)
  • https://api.github.com/repos/sebastianbergmann/version/zipball/c6c1022351a901512170118436c764e473f6de8c
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/r8gnS3 /usr/bin/composer install (http block)
  • https://api.github.com/repos/theseer/tokenizer/zipball/737eda637ed5e28c3413cb1ebe8bb52cbf1ca7a2
    • Triggering command: /usr/bin/php8.3 -n -c /tmp/r8gnS3 /usr/bin/composer install (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

This section details on the original issue you should resolve

<issue_title>GET after PUT</issue_title>
<issue_description>CURLOPT_CUSTOMREQUEST is not cleared after a PUT request, causing a GET request with the same object instance to fail (because it's still trying to PUT). Same misbehavior applies to DELETE and PATCH.</issue_description>

Comments on the Issue (you are @copilot in this section)

@nadar thanks for the report @steffstuff. Can you please make a full code example. thanks @nadar AFAIK, this is not the intended use of it. You should always use $curlObj = new Curl(). This is also the reason why there’s no such concept of a base URL definition (for subsequent calls). Nevertheless, yes, I think we should fix that.

💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

Copilot AI and others added 2 commits November 5, 2025 13:53
…tence issue

Co-authored-by: nadar <3417221+nadar@users.noreply.github.com>
Co-authored-by: nadar <3417221+nadar@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix CURLOPT_CUSTOMREQUEST not clearing after PUT requests Clear CURLOPT_CUSTOMREQUEST in get() and post() to fix request method persistence Nov 5, 2025
Copilot AI requested a review from nadar November 5, 2025 14:01
Copilot finished work on behalf of nadar November 5, 2025 14:01
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

GET after PUT

2 participants