Uploaded image for project: 'PHP Driver: Extension'
  1. PHP Driver: Extension
  2. PHPC-2004

Specify string return type in __toString() arginfos

    • Type: Icon: Improvement Improvement
    • Resolution: Fixed
    • Priority: Icon: Unknown Unknown
    • 1.12.0
    • Affects Version/s: None
    • Component/s: None
    • Labels:
      None

      php/php-src@b302bfa recently introduced automatic implementation of Stringable for internal classes the implement a __toString() method. This results in several new errors when loading the extension with PHP 8.1.0RC6-dev due to conflicting arginfo:

      Declaration of MongoDB\BSON\BinaryInterface::__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)
        // ...
      

      In php-src, _ZendTestClass uses ZEND_BEGIN_ARG_WITH_RETURN_TYPE_INFO_EX to declare a string return type. We should likely do the same in our classes.

            Assignee:
            jmikola@mongodb.com Jeremy Mikola
            Reporter:
            jmikola@mongodb.com Jeremy Mikola
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Created:
              Updated:
              Resolved: