Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83666 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 90622 invoked from network); 24 Feb 2015 14:29:22 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Feb 2015 14:29:22 -0000 Authentication-Results: pb1.pair.com smtp.mail=dennis@birkholz.biz; spf=unknown; sender-id=unknown Authentication-Results: pb1.pair.com header.from=dennis@birkholz.biz; sender-id=unknown Received-SPF: unknown (pb1.pair.com: domain birkholz.biz does not designate 144.76.185.252 as permitted sender) X-PHP-List-Original-Sender: dennis@birkholz.biz X-Host-Fingerprint: 144.76.185.252 mx01.nexxes.net Received: from [144.76.185.252] ([144.76.185.252:43642] helo=mx01.nexxes.net) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id E8/22-10521-1CA8CE45 for ; Tue, 24 Feb 2015 09:29:22 -0500 Received: from [137.226.183.192] (ip3192.saw.rwth-aachen.de [137.226.183.192]) (using TLSv1 with cipher DHE-RSA-AES128-SHA (128/128 bits)) (No client certificate requested) (Authenticated sender: db220660-p0g-1@packages.nexxes.net) by mx01.nexxes.net (Postfix) with ESMTPSA id 1EB6C48245A for ; Tue, 24 Feb 2015 15:29:18 +0100 (CET) Message-ID: <54EC8ABD.7040802@birkholz.biz> Date: Tue, 24 Feb 2015 15:29:17 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: internals@lists.php.net References: In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] [RFC] Anonymous Classes From: dennis@birkholz.biz (Dennis Birkholz) Hi Phil, Am 24.02.2015 um 14:52 schrieb Philip Sturgeon: > https://wiki.php.net/rfc/anonymous_classes I like the idea of having anonymous classes, it is very helpful during development to just try something out without having the burden of creating a new file and a complete class including namespace and use declarations, etc. A great feature of anonymous classes in Java is their ability to access the private/protected properties of the object they are defined in, similar to what Closures do in PHP. The thing is, in Java if you access a variable (without this.), it may be of the current scope, a member of the current class or a member of the class where the anonymous class was defined in. In PHP, you have to use $this-> to access class members of the anonymous class but there is some $outer-> or similar variable missing for the access. You can as a work around pass all members by reference via the constructor, but that is really not nice. In addition, if you define an anonymous class inside a "real" class and pass another instance of the outer class, the anonymous class can still access the private/protected methods imho. Any thoughts how to handle this or should we just ignore it for now? Second thing is serialization. PHP closures can not be serialized, does the same apply for anonymous classes? It would be really nice if such anonymous classes could e.g. send via a command bus or something to be executed on another host. Thanks Dennis P.s.: there is a footnote in the RFC that does not belong there is think