Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83672 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 2626 invoked from network); 24 Feb 2015 15:33:27 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Feb 2015 15:33:27 -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.217.172 as permitted sender) X-PHP-List-Original-Sender: pjsturgeon@gmail.com X-Host-Fingerprint: 209.85.217.172 mail-lb0-f172.google.com Received: from [209.85.217.172] ([209.85.217.172:34643] helo=mail-lb0-f172.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 55/44-10521-6C99CE45 for ; Tue, 24 Feb 2015 10:33:26 -0500 Received: by lbdu14 with SMTP id u14so25566119lbd.1 for ; Tue, 24 Feb 2015 07:33:23 -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=iDDxC54uddfE09pQEB4YLFuIbrTDN466xB/kObBVFGc=; b=ktN6HTCX0ASuHbQahGLDkgYO54cfUupj/c6J39MmhwDo6zzunOJnH4MjiCb2uiDLZi hcNRoT8gQ5ElEA9l04Xo/7eYVVbT8EiRNpuR3i9WKLDDtPivv5g9qPKBv0NOc9JDHoIw wgYU8FZvoQo30naopNiUrFqwhQwnpErWUNVtiPMJIWsBmuMrTLqqxL8UH/OYR/rHS7aO Mq5I2QeEBSapxKHKMJjUl3jl2KpM6HvJkcQhdTXXZODdIMXMxwIP8nC7bt2B9WWX9x17 A5aZ73cWk9dD1jggHV7ls40tU4Jwcp5RfdeCu3NX3V10hDRgH0M0f7KeTt1z+Sd9Xfwe NdGA== MIME-Version: 1.0 X-Received: by 10.152.3.70 with SMTP id a6mr14655820laa.71.1424792003641; Tue, 24 Feb 2015 07:33:23 -0800 (PST) Received: by 10.114.26.34 with HTTP; Tue, 24 Feb 2015 07:33:23 -0800 (PST) In-Reply-To: References: Date: Tue, 24 Feb 2015 10:33:23 -0500 Message-ID: To: Dmitry Stogov Cc: PHP Internals 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 9:34 AM, Dmitry Stogov wrote: > > > On Tue, Feb 24, 2015 at 5:19 PM, Philip Sturgeon > wrote: >> >> On Tue, Feb 24, 2015 at 9:10 AM, Dmitry Stogov wrote: >> > I think the proposal is a bit incomplete. >> > It's possible to instantiate an anonymous class, but currently it's not >> > possible to do with them anything else (assign to variable, pass to >> > function, etc). Something similar to Closure objects should be >> > introduced. >> > >> > Thanks. Dmitry. >> >> 1. You can absolutely assign the instantiated classes to variables. >> >> Check out this test in the patch: >> >> https://github.com/krakjoe/php-src/compare/anon#diff-25e330fb5a98810de178a5b798102d01R1 >> > > In tests you assign instantiated objects. > > $a = new class {...}; > $b = new class {...}; > > I'm talking about classes as first class objects. > > $c = class {...}; > $a = new $c; > $b = new $c; > > >> >> 2. Why do you say they cannot be passed to a function? I can add a >> test if you can give me an example of what you're suggesting doesn't >> work. >> >> 3. Not sure why we'd need a Closure-alike object. Anonymous classes >> are just a class, and classes have all the types and hinting >> functionality of regular classes. You don't need to implement a class >> to let people know its a class. >> >> Maybe you could expand on that a bit? :) > > > I tried it in the example above. > > Also, classes may be useful without objects at all (just static properties > and methods). > > $c = class {...}; > $c::static_foo(); > > Thanks. Dmitry. Thank you for the example! Your example explains my question 1, but doesn't seem to explain 2 or 3. I'll play around with static usage and show it off in the tests.