Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:65906 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 18510 invoked from network); 18 Feb 2013 15:43:13 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 18 Feb 2013 15:43:13 -0000 Authentication-Results: pb1.pair.com smtp.mail=rasmus@mindplay.dk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=rasmus@mindplay.dk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain mindplay.dk from 209.85.212.48 cause and error) X-PHP-List-Original-Sender: rasmus@mindplay.dk X-Host-Fingerprint: 209.85.212.48 mail-vb0-f48.google.com Received: from [209.85.212.48] ([209.85.212.48:36554] helo=mail-vb0-f48.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D3/50-14899-F0C42215 for ; Mon, 18 Feb 2013 10:43:12 -0500 Received: by mail-vb0-f48.google.com with SMTP id fc21so3573476vbb.21 for ; Mon, 18 Feb 2013 07:43:08 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20120113; h=mime-version:x-received:date:message-id:subject:from:to :content-type:x-gm-message-state; bh=MGlGYn7FQ/l/Hs+Ew3DY35Q9z9Le3iLEdF8DBW1dljU=; b=byvukX8iq8dIYn/CZmPPqdMpP+2G9Fn+P8Me2ZqokCPWhOhWksaBl0BtLggyBzyd70 fDlWJhfkkov220ZiTwa2hvk0M/HZSBZ+hnqEEEg5jP+b7a90TYobgHdkUQaG6XKCQufL k9s9V8z8WsceAC+OZa++/MzULmwTCiwIO9JbbC6Oh4vdfPlsy+RP8+Dh9wEmxiaGNGV5 JdCIRct4Mc4f+p933pLxKgsW0h+DiwKZn3OpIsXZVzG1eYVGSHo33Oz29PA2Q8vzo38r /HOW2izV7cSsJMdJ81eZ7PXZwajNe5qYphGfj4C1t5oIwMUQF2xMmQ2RVv0B3cGkAlHc EW+w== MIME-Version: 1.0 X-Received: by 10.220.220.134 with SMTP id hy6mr16018971vcb.2.1361202188167; Mon, 18 Feb 2013 07:43:08 -0800 (PST) Received: by 10.58.102.137 with HTTP; Mon, 18 Feb 2013 07:43:08 -0800 (PST) Date: Mon, 18 Feb 2013 10:43:08 -0500 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=14dae9cfcb9ae4a81104d60194c2 X-Gm-Message-State: ALoCoQnItYbkKZ070Sx4y9rQGvD0gqdYUQAVwRrUCTcRsqq25zWDlG6q8qZnIUgGDpsIXuSpvCLd Subject: short syntax for construction/initialization, named arguments and (future) annotations From: rasmus@mindplay.dk (Rasmus Schultz) --14dae9cfcb9ae4a81104d60194c2 Content-Type: text/plain; charset=ISO-8859-1 This is a not a feature request, just a note on something that occurred to me. Since there is talk of native support for annotations again, it occurred to me that part of the problem that every userland implementation and proposed syntax deals with, along with native implementations in other languages, is that of convenient short-hand syntax for construction and initialization (of annotation objects.) A constructor is a method with arguments, so a single familiar syntax really could (perhaps should) be applicable in all of those cases. How about something like this? class Foo { public $bling; public function __construct($bar, $baz) { .... } // (sample annotation) public function setName($first, $last) { .... } } $test = new Foo({ bar='bar'; baz=123 }) { bling = 'wibble' }; // equivalent to: // $test = new Foo('bar', 123); // $test->bling = 'wibble'; $test->setName({ last='Kong'; first='Donkey' }); // equivalent to: // $test->setBar('Donkey', 'Kong'); So in other words, a unified syntax for named (constructor and method) arguments, and property-initialization with the "new" keyword - all of which could be statically checked (in IDEs), as could the property-values for an annotation instance. This could mitigate a lot of crappy stuff you see in (even the leading) frameworks right now, where far too frequently, initialization and configuration, as well as "named arguments", are implemented as nested arrays, to which you cannot apply any kind of static analysis. Proposed annotation syntaxes (and some syntaxes in other languages) typically address this issue by introducing special syntax for annotations, which are a good example of where property-initialization is heavily used and benefits greatly from static checking, auto-complete in IDEs, etc. Just throwing that thought out there. Try not to get hung up on the syntax in the example above, I just came up with something on the spot, just to provide some context. --14dae9cfcb9ae4a81104d60194c2--