httpful icon indicating copy to clipboard operation
httpful copied to clipboard

Support for PHP8+

Open adcomdatamolde opened this issue 1 year ago • 4 comments

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 avatar Apr 26 '23 08:04 adcomdatamolde

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;

adcomdatamolde avatar Apr 26 '23 11:04 adcomdatamolde

Thanks for the tips

cperves avatar May 11 '23 08:05 cperves

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

JPaulMora avatar Dec 02 '23 04:12 JPaulMora

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

mmplnt avatar Jan 11 '24 16:01 mmplnt

Support was added for 8.0+.

nategood avatar Jul 31 '24 12:07 nategood

Thanks a lot @nategood

JPaulMora avatar Jul 31 '24 17:07 JPaulMora