Import function with php 5.4

Asked

Viewed 33 times

0

I am using an API, but it was designed to work in php 5.6+, but my server is with version 5.4, alias, my server is not the client server and this client server already has several applications running in 5.4 so it would be more complex to update, since I don’t know these applications and they are huge, so I’m trying to adapt this API to run in version 5.4, it was happening all right, I found several alternatives until I found this:

use function GuzzleHttp\Psr7\modify_request;

Where it imports a function from a particular file, wanted to know if there is an alternative to import this function using php 5.4.

  • If you remove the function works? already need some more work when calling the function.

  • @rray apparently worked, I am running the api and fixing the errors that are appearing, I took Function and gave no more error in this function, thank you! If at the end of the modifications rotate I put here everything worked out!

  • 1

    Manage to put a bar in front, this way: Guzzlehttp Psr7 modify_request(...

1 answer

1


The use function is supported only by PHP5.6+, as well as with constants:

use const Foo\Bar\CONSTANT;

Now concerning the functions in https://github.com/guzzle/psr7/blob/master/src/functions.php you can simply import the functions_include.php and use the function directly GuzzleHttp\Psr7\modify_request(..., ...); and do not use the use function:

<?php

use GuzzleHttp\Psr7\Request;

require_once 'vendor/guzzlehttp/psr7/src/functions_include.php';
require_once 'vendor/autoload.php';

$request = new Request('GET', 'https://answall.com');

$request = GuzzleHttp\Psr7\modify_request($request, [ 'set_headers' => [ 'foo' => 'bar' ] ]);

Browser other questions tagged

You are not signed in. Login or sign up in order to post.