httpful
httpful copied to clipboard
Support for PHP8+
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?
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;
Thanks for the tips
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
https://github.com/Hat3/httpful/tree/php_8.1
Support was added for 8.0+.
Thanks a lot @nategood