Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:83683 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 29288 invoked from network); 24 Feb 2015 19:06:25 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Feb 2015 19:06:25 -0000 Authentication-Results: pb1.pair.com header.from=ua.san.alex@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=ua.san.alex@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.176 as permitted sender) X-PHP-List-Original-Sender: ua.san.alex@gmail.com X-Host-Fingerprint: 209.85.223.176 mail-ie0-f176.google.com Received: from [209.85.223.176] ([209.85.223.176:46148] helo=mail-ie0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 51/B0-24698-0BBCCE45 for ; Tue, 24 Feb 2015 14:06:25 -0500 Received: by iecvy18 with SMTP id vy18so34567272iec.13 for ; Tue, 24 Feb 2015 11:06:21 -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=Qs3v5ObzLHVYU2mK1Cj86otgada9dgtunQOf3q22rXo=; b=V4QN+DwiWZnYhntVCfviO1/GbAcsZ0j5nvzhY4xeDCtN8Zo6+rGXJd02bHYo9x/JM1 itxmvsMQUO0UtxeOlnFGFgUJmkSCYrQzIRkfbTbXzM0rl838vLAl2aguT/rPbPfYOHsv sMLP8cBdfxFz8Y6Zvoe0hXx2fSPGzRNlnv5VEXdRzmFxyp5PPBiMWQmobHghtLnkTx1W ioDuAZxjeLKsGUxZPUzrOr8K9LdX91YOh5oM15+zgWOY64MPmrVtlFVxhRIO4EvygxTw d5D8uwsJ1HAG2pD8FfyLGfrmh5sQAkSrwVPbq/qTJtVJRKI0S7ZwMm73J++TY1aezPkO RQrw== MIME-Version: 1.0 X-Received: by 10.107.7.154 with SMTP id g26mr21985393ioi.64.1424804780995; Tue, 24 Feb 2015 11:06:20 -0800 (PST) Received: by 10.50.93.3 with HTTP; Tue, 24 Feb 2015 11:06:20 -0800 (PST) In-Reply-To: References: Date: Tue, 24 Feb 2015 21:06:20 +0200 Message-ID: To: Philip Sturgeon Cc: Mike Willbanks , PHP Internals Content-Type: text/plain; charset=UTF-8 Subject: Re: [PHP-DEV] [RFC] Anonymous Classes From: ua.san.alex@gmail.com ("S.A.N") 2015-02-24 20:49 GMT+02:00 Philip Sturgeon : > On Tue, Feb 24, 2015 at 1:37 PM, S.A.N wrote: >> Would have been more useful, inline sintex like JSON: >> >> $object = >> { >> 'property': $value, >> 'method': function (){...} >> }; >> >> $object->property; >> $object->method(); > > I know what you're saying here, and object literals like this would be > rather interesting someday. They are, however, quite different to the > concept of anonymous classes. > > JSON syntax would make it very hard for the usual PHP functionality to > be used. Properties and methods look the same, visibility scopes > cannot be used, implementing interfaces becomes impossible, traits > dont have a home, etc. By the time you have catered to all of that you > have something very different to JSON, and very different to PHP. > > Or, you have the syntax being proposed here, which is identical to > existing declared class syntax other than there being no name. > > Another RFC to replace $foo = (object) [ 'foo' => 'bar' ]; someday > would be nice, but that is not what this is up to. Yes, is problem - properties and methods look the same, how to solve this problem in PHP I do not know. Perhaps PHP could interpret this code: $object = { 'property' => $value, 'method' => function (){...} }; AS $object = new class { public $property = $value; public function method (){...} } Use case - inline object without inheritance and traits, only the properties and methods it brief and easily understood JSON syntax, I think it would be popular with developers of PHP. Thank.