Guzzle: Call to undefined function GuzzleHttp\_idn_uri_convert()

Created on 27 Dec 2019  路  3Comments  路  Source: guzzle/guzzle

Guzzle version(s) affected: 6.5.x-dev
PHP version: 7.1.33
cURL version: 7.19.7

Description
After updating Guzzle via composer, the following error occurs when running our application:

Throwable error occurred: Call to undefined function GuzzleHttp\_idn_uri_convert()

The exception trace:

{
    "class": "Error",
    "message": "Call to undefined function GuzzleHttp\\_idn_uri_convert()",
    "code": 0,
    "file": "/nfs/web/vendor/guzzlehttp/guzzle/src/Client.php:220",
    "trace": [
        "/nfs/web/vendor/guzzlehttp/guzzle/src/Client.php:155",
        "/nfs/web/vendor/guzzlehttp/guzzle/src/Client.php:183",
        "/nfs/web/vendor/guzzlehttp/guzzle/src/Client.php:96",
        "/nfs/web/vendor/x/y/src/JsonRpc/Client.php:207", # $response = $this->http->post($request_url, $opts);
...
        "/nfs/web/lib/php/app/public/index.php:50"
    ]
}

I'm not sure why this function is undefined. It does exist in functions.php in the GuzzleHttp namespace. Trying to add require_once __DIR__ . '/functions.php'; above that call results in: Fatal error: Cannot redeclare GuzzleHttp\json_encode() (previously declared in ./vendor/guzzlehttp/guzzle/src/functions.php:323) in ./vendor/guzzlehttp/guzzle/src/functions.php on line 326

How to reproduce

Instantiate a new GuzzleHttp client and attempt to make a request.

Possible Solution

Set the option idn_conversion to false in the Guzzle client options. Use dev-master or 7.x.

Additional context

This was not a problem until the following commit approximately 15 days ago: https://github.com/guzzle/guzzle/blame/43ece0e75098b7ecd8d13918293029e555a50f82/src/Client.php#L242-L250

Using the master branch resolves the issue because it does not have this code change and idn_conversion still defaults to false.

function_exists('idn_to_ascii') : true

defined('INTL_IDNA_VARIANT_UTS46') : false

PHP_VERSION_ID < 70200 : true (70133)

Most helpful comment

Hi @gmponos,

Thank you for the quick response and test. NFS turned out not to be the issue but rather a "subapplication" within the main application was autoloading an earlier version of guzzle.

So this turned out to the result of poor design and then having 2 composer autoloaders mixing up with eachother.

Running composer update in the subapplication resolved the issue, as it was autoloading the functions.php from the older guzzle version:

  - Updating guzzlehttp/guzzle (6.3.3 => 6.5.2): Loading from cache

Sorry for not realizing this or spending more time trying to resolve it.

All 3 comments

I have to ask, because I have seen issues like this in the past... and as you said the function exists...

I see that you use /nfs could it be that the files are not synced for any reason? So the functions file in the nfs does not contain the latest changes...?

composer.json:

{
    "name": "gmponos/guzzle-issue-2502",
    "authors": [
        {
            "name": "Mponos George",
            "email": "[email protected]"
        }
    ],
    "require": {
        "guzzlehttp/guzzle": "^6.5"
    }
}
<?php

require_once 'vendor/autoload.php';

$client = new GuzzleHttp\Client();
$response = $client->request('get', 'www.google.com', [
    \GuzzleHttp\RequestOptions::IDN_CONVERSION => true,
]);

var_dump($response->getStatusCode()); // outputs 200

I have also added a var_dump inside _idn_uri_convert and the code above reached there..

Instantiate a new GuzzleHttp client and attempt to make a request.

Is it possible you could provide more details on how to reproduce?

Hi @gmponos,

Thank you for the quick response and test. NFS turned out not to be the issue but rather a "subapplication" within the main application was autoloading an earlier version of guzzle.

So this turned out to the result of poor design and then having 2 composer autoloaders mixing up with eachother.

Running composer update in the subapplication resolved the issue, as it was autoloading the functions.php from the older guzzle version:

  - Updating guzzlehttp/guzzle (6.3.3 => 6.5.2): Loading from cache

Sorry for not realizing this or spending more time trying to resolve it.

Was this page helpful?
0 / 5 - 0 ratings