Re: RFC: Functional Interfaces
| From: | Dmitry Stogov | Date: | Tue, 19 Apr 2016 13:22:19 +0000 |
| Subject: | Re: RFC: Functional Interfaces | ||
| References: | 1 2 3 4 | Groups: | php.internals |
| Request: | Send a blank email to internals+get-92455@lists.php.net to get a copy of this message | ||
On 04/19/2016 03:52 PM, Joe Watkins wrote:
Oh, it's confusing text in the RFC, using the word "Interface" ... that's meant as a placeholder for InterfaceName. Cheers Joe On Tue, Apr 19, 2016 at 1:50 PM, Joe Watkins <pthreads@pthreads.org <mailto:pthreads@pthreads.org>> wrote:OK. so this is not just a syntax sugar, but if you implement lexical scope for anonymous classes it's going to be sugar. Right? May be it's better to start from classes first?Morning Dmitry,In your example, they will do the same thing.Anon classes don't have lexical scope, I have a patch for that, and an RFC, I'm just tidying it.
Even when anon classes do have lexical scope, there is value in
being able to implement these kinds of interfaces using only a
function.
What value? just shorter syntax? or anything else?
The changes to the vm are restricted to a few lines, that's not
seriously a problem, is it !?
I hope no. I didn't understand all details of proposal and I didn't take a deep look into the code.
I meant new field zend_execute_data *interface in zend_closure structure. I thought the same might be implemented through anonymous classes. Thanks. Dmitry.I don't see where I extend closure with an interface ...
zend_do_inheritance_ex(type, zend_ce_closure, 1); zend_class_implements(type, 1, interface);Cheers JoeOn Tue, Apr 19, 2016 at 1:01 PM, Dmitry Stogov <dmitry@zend.com <mailto:dmitry@zend.com>> wrote:<?php interface IFoo { public function method() : int; }$cb1 = function () implements IFoo : int { return 42; };$cb2 = new class implements IFoo { function method() : int { return 42; } }; ?>Are $cb1 and $cb2 going to be the same (do the same)? Is this just a new syntax sugar, or a really new feature?According to implementation, I think, you shouldn't extend "zend_closure" with "interface". If this is a sugar, lets implement it as a sugar (without VM changes).But may be I didn't understand the idea at all :)Thanks. Dmitry.________________________________________ From: Joe Watkins <pthreads@pthreads.org <mailto:pthreads@pthreads.org>> Sent: Monday, April 18, 2016 13:22 To: PHP internals Subject: [PHP-DEV] RFC: Functional InterfacesMorning Internals,Please review the following RFC:https://wiki.php.net/rfc/functional-interfacesAn implementation is provided, and is testable on 3v4l.Review of the implementation from those of you that do that would be good :)Cheers Joe