Return types

This is a pull request to implement the return type RFC: https://wiki.php.net/rfc/returntypehinting

Notes about the implementation:

  - Adds a new opcode `ZEND_VERIFY_RETURN_TYPE`. When a function has a return type, this opcode will be emitted to check that the return value satisfies the return type.
  - When a class method uses return types, the class is no longer early bound. This is because the covariance checks must be done at runtime when the return types are objects. Presently any return type will remove the early binding.
  - `class_uses_return_types` loops through all the methods to see if any of them have a return type; there should probably be a flag on the class entry that is enabled whenever a return type is used instead of looping all the time.
  - Internal classes cannot specify return types, at least not easily.
  - During `pass_two` if a `ZEND_VERIFY_RETURN_TYPE` opcode is found in a `Generator` then it will be made into a no-op. It would be nicer to not emit one for generators, but this is somewhat difficult to do because when you process the `return` expression you may not know if the function is a generator yet.
I see op2, only used as IS_VAR on line 2819, but I think it must be
possible to use EX(func).common.return_type.name instead. (I'm not
completely sure).

On Thu, Oct 16, 2014 at 11:37 AM, Levi Morrison <notifications@github.com>
wrote:

> In Zend/zend_vm_def.h:
>
> > @@ -2795,6 +2795,51 @@ ZEND_VM_C_LABEL(fcall_end):
> >  	ZEND_VM_NEXT_OPCODE();
> >  }
> >
> > +ZEND_VM_HANDLER(170, ZEND_VERIFY_RETURN_TYPE, ANY, VAR|UNUSED)
>
> I'm not sure about op1. Presently op2 is VAR|UNUSED and no more. This
> part of the code I don't really understand that well. I hate the magic
> going on here.
>
> —
> Reply to this email directly or view it on GitHub
> <https://github.com/php/php-src/pull/820/files#r18941403>.
>