Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:84535 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 10836 invoked from network); 11 Mar 2015 10:35:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Mar 2015 10:35:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=leedavis81@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=leedavis81@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.179 as permitted sender) X-PHP-List-Original-Sender: leedavis81@gmail.com X-Host-Fingerprint: 209.85.213.179 mail-ig0-f179.google.com Received: from [209.85.213.179] ([209.85.213.179:45775] helo=mail-ig0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 2D/70-07702-35A10055 for ; Wed, 11 Mar 2015 05:35:00 -0500 Received: by igjz20 with SMTP id z20so10415910igj.4 for ; Wed, 11 Mar 2015 03:34:57 -0700 (PDT) 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=g3ZzQGUQqUZgtIj5+dIszbDcZtZDZongT4kqlHf9VrU=; b=FC232Gf2FBlbvueuACx6dt8yfmMLJdpliZslLReTcXxw7AjE7rl2iyGXS29v8ycb0F efT3BJNTK+GtoVtl1YytwNgyLHBuotwXP9+amnWBTcW1T1QMxM0yUPR74e5nCu1sPJt8 1y7txQieJhEygIr0WLq8hwxZarPE7k2A1W14E4cAfrdj3HQ8pFyX9iiqD8VGUQm9Xozo 2kB0DhwUAwiCQJ9rMpWmGBeJkuFd7liBUuQN18g9Q9ARL2JuSZr8jMxjGS3uViTM2HNb uziLyLgySVTqokNVOwOIbspQoKhPnKayjRiH2mv9oPblmcyoC7tza0ldUzaKfkqRVWV3 QnZA== MIME-Version: 1.0 X-Received: by 10.107.132.13 with SMTP id g13mr30913827iod.4.1426070097318; Wed, 11 Mar 2015 03:34:57 -0700 (PDT) Received: by 10.36.92.202 with HTTP; Wed, 11 Mar 2015 03:34:57 -0700 (PDT) In-Reply-To: References: Date: Wed, 11 Mar 2015 10:34:57 +0000 Message-ID: To: Philip Sturgeon Cc: PHP Internals Content-Type: multipart/alternative; boundary=001a113eca66935ab5051100d19b Subject: Re: [PHP-DEV] [RFC] Anonymous Classes From: leedavis81@gmail.com (Lee Davis) --001a113eca66935ab5051100d19b Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Hi Phil. I really like this feature and am keen to see it go in. Developers often create classes (which are typically new files) just to extend and implement a small method. This feature could see codebases become much lighter. So a massive thanks for your and Joe=E2=80=99s efforts on this. I have two quite small points I want to make. Firstly, When a error occurs on an anonymous class the class description isn=E2=80= =99t very useful (see http://3v4l.org/9Nbea/rfc#tabs). Instead of =E2=80=9Cclass@0x7f9e33870fd0=E2=80=9D Is it possible it could be prefixed = with =E2=80=9Canonymous=E2=80=9D or something a bit clearer. Further to this if the anonymous class extends anything it omits the parent class name in the error message (see http://3v4l.org/UFEbo/rfc#tabs). Is this expected? Could it be something more helpful? Secondly, I think we need to either allow the behaviour or generate an error (similar to anonymous closures) when an anonymous class is serialized. Please observe the following behaviour.. $foo =3D new class { public function Bar () { echo 'bar'; } }; // This succeeds. I'd argue an error should be generated at this point echo $serFoo =3D serialize($foo); // Unserialize fails and a notice is generated $unFoo =3D unserialize($serFoo); // Error generated on call $unFoo->Bar(); see http://3v4l.org/AJY6d/rfc#tabs That=E2=80=99s all. Again, thanks for your efforts. /@leedavis81 On Tue, Feb 24, 2015 at 1:52 PM, Philip Sturgeon wrote: > Good day! > > https://wiki.php.net/rfc/anonymous_classes > > There's a little RFC + patch that Joe Watkins put together, and as > before with the ArrayOf RFC, I'll be helping out. > > So, lets get this discussion rolling. > > It was declined for PHP 5 some time ago, and has returned now to try for > PHP 7. > > The usage of anonymous classes to some will be instantly offensive, > but really it comes down to the use case. The usage of anonymous > functions compared to declared functions is pretty much the exact same > thing as anonymous classes. > > Other than examples on the RFC, Fractal would certainly be happy to > have them: http://fractal.thephpleague.com/transformers/ > > Defining a class properly is certainly still going to be the majority > of uses of classes in PHP. That helps with the Optimizer, and helps > code reuse. > > Sadly due to the way in which people have had ONE CLASS ONE FILE > drilled into their head since PEAR and continuing through Zend and > PSR-0, it can become a PITA to add some simple functionality if a > small class is needed for one tiny thing. > > Anonymous functions alleviate that annoyance with a simple and > consistent feature that just give people a nice simple option to get > their jobs done, without hitting autoloaders and file systems to do > it. > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > --001a113eca66935ab5051100d19b--