https://github.com/php/php-src/commit/b302bfabe7fadd07b022ee30aacf7f41ab1ae0fa
recently added automatic implementation of Stringable (
https://wiki.php.net/rfc/stringable) for internal classes. This introduced
fatal errors for each existing __toString() in ext-mongodb:

```
Declaration of MongoDB\BSON\BinaryInterface::__toString() must be
compatible with Stringable::__toString(): string in Unknown on line 0
Declaration of MongoDB\BSON\Binary::__toString() must be compatible with
Stringable::__toString(): string in Unknown on line 0
...
```

Our arginfos for these methods have historically never reported a return
type, going back to when it was originally written for PHP 5.x. For example:

```
ZEND_BEGIN_ARG_INFO_EX(ai_BinaryInterface_void, 0, 0, 0)
ZEND_END_ARG_INFO()

static zend_function_entry php_phongo_binary_interface_me[] = {
  ZEND_ABSTRACT_ME(BinaryInterface, __toString, ai_BinaryInterface_void)
  // ...
```

I noted that _ZendTestClass (referenced in the original commit's tests)
uses ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX to declare a string return
type (
https://github.com/php/php-src/blob/eda9d7ac22c70f75a44bf33139acf8c812d69944/ext/zend_test/test_arginfo.h#L74
).

While that's a trivial change we can make in ext-mongodb, I wonder if this
may have been an unanticipated BC break for third-party extensions. I
imagine ext-mongodb is not the only extension with older arginfo
declarations predating the introduction of type reporting in later PHP
versions.

-- 
jeremy mikola

Reply via email to