Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83810 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 752 invoked from network); 25 Feb 2015 17:49:07 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 25 Feb 2015 17:49:07 -0000 Authentication-Results: pb1.pair.com smtp.mail=pjsturgeon@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=pjsturgeon@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.215.45 as permitted sender) X-PHP-List-Original-Sender: pjsturgeon@gmail.com X-Host-Fingerprint: 209.85.215.45 mail-la0-f45.google.com Received: from [209.85.215.45] ([209.85.215.45:43769] helo=mail-la0-f45.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D3/22-20665-01B0EE45 for ; Wed, 25 Feb 2015 12:49:06 -0500 Received: by labhv19 with SMTP id hv19so5535500lab.10 for ; Wed, 25 Feb 2015 09:49:02 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :cc:content-type; bh=/mwWbwHnjOZlT9Ij4g4uSEYFbVhFj+eNvucuqa/FmP8=; b=jzogow2Lw7KxNIUQz3dUeZyzmXxTd1OUNdNBIZesd4uZBMeSKMQgNQwkRFPPnIYbbU OzMMuHt2N/E9p/hMQ9+jUUZ/00zSgWEA/+IIszv7+WjxsBxE8mIdvNpCBDMvlx3/MCq2 8icxNem9L8rRVu+igRdx8O2k61e2B/FnPcaxo2tW6/yH6u6sinfA0VwPbO5QGDmelhPs ZEyaBYD3rJJnWNk0lQLbipoNEofF+7LMO625prhgwBfNUSknqO8t2B5oaDPkXbaoG/RS G/qWODZhw690p9QcTthWxCjNI8KK6J5ZdAvq0mZg8uMEnfm+FQFVJHRc1T10BLMQm1Rl hWvg== MIME-Version: 1.0 X-Received: by 10.152.7.204 with SMTP id l12mr3907825laa.1.1424886542190; Wed, 25 Feb 2015 09:49:02 -0800 (PST) Received: by 10.114.26.34 with HTTP; Wed, 25 Feb 2015 09:49:02 -0800 (PST) In-Reply-To: <54ECD042.7070800@gmail.com> References: <54EC8ABD.7040802@birkholz.biz> <54ECD042.7070800@gmail.com> Date: Wed, 25 Feb 2015 12:49:02 -0500 Message-ID: To: Stanislav Malyshev Cc: Dennis Birkholz , "internals@lists.php.net" Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Anonymous Classes From: pjsturgeon@gmail.com (Philip Sturgeon) On Tue, Feb 24, 2015 at 2:25 PM, Stanislav Malyshev wrote: > Hi! > >> 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. > > I think this particular argument is a bit backwards. In PHP, you > certainly don't need to create new file to just introduce a new class. > If you're working within a framework that makes it a problem, time to > think if the framework you're using is fit for your purposes. But PHP > certainly does not impose such limitations. > >> 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 > > That may be a problem to implement, exactly since you need $this in PHP. > >> Second thing is serialization. PHP closures can not be serialized, does >> the same apply for anonymous classes? It would be really nice if such > > Serializing is not a problem, unserializing would be - as there may be > no class for this object to instantiate. > > -- > Stas Malyshev > smalyshev@gmail.com > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > If anyone wants to have a play with anonymous classes, our friends over at 3v4l.org have made this incredibly easy to do: http://3v4l.org/elh6I/rfc#rfc-anonymous_classes Awesome.