nategood / httpful

A Chainable, REST Friendly, PHP HTTP Client. A sane alternative to cURL.
MIT License
1.74k stars 298 forks source link

Support for PHP8+ #304

Closed adcomdatamolde closed 1 month ago

adcomdatamolde commented 1 year ago

I am upgrading to PHP version 8.0.28, and find multiple errors in this library. I can't see any new branch for supporting PHP8+, or plans to add PHP8+ support in documentation or in other issues.

Last update of this library was 3 years ago. Anyone working on PHP8+ support?

adcomdatamolde commented 1 year ago

If people need a fix in the meantime, until PHP8 support is added, read this:

You will get error messages saying functions are not compatible with return type. Typical this error appears for multiple function is Response\Headers.php Example:

        /**
         * @param string $offset
         * @return bool
         */
        public function offsetExists($offset)
        {
            return $this->getCaseInsensitive($offset) !== null;
        }

Fix this by adding the comment starting with # like this:

        /**
         * @param string $offset
         * @return bool
         */
        #[\ReturnTypeWillChange]
        public function offsetExists($offset)
        {
            return $this->getCaseInsensitive($offset) !== null;
        }

Read more about this here: https://php.watch/versions/8.1/ReturnTypeWillChange

You will also get an error saying dynamically adding properties are not allowed, like the timeout property in Request class. Just add the property in the list in the beginning of the class:

           $max_redirects           = self::MAX_REDIRECTS_DEFAULT,
           $payload_serializers     = array(),
           $timeout;
cperves commented 1 year ago

Thanks for the tips

JPaulMora commented 9 months ago

I have just tested https://github.com/sosherof/httpful/tree/PHP7.2_to_8.2 this version and it's all working great on PHP 8.1

mmplnt commented 7 months ago

https://github.com/Hat3/httpful/tree/php_8.1

nategood commented 1 month ago

Support was added for 8.0+.

JPaulMora commented 1 month ago

Thanks a lot @nategood