Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93680 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 67801 invoked from network); 1 Jun 2016 15:47:34 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jun 2016 15:47:34 -0000 Authentication-Results: pb1.pair.com smtp.mail=derokorian@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=derokorian@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.218.46 as permitted sender) X-PHP-List-Original-Sender: derokorian@gmail.com X-Host-Fingerprint: 209.85.218.46 mail-oi0-f46.google.com Received: from [209.85.218.46] ([209.85.218.46:36672] helo=mail-oi0-f46.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 65/80-63812-5930F475 for ; Wed, 01 Jun 2016 11:47:33 -0400 Received: by mail-oi0-f46.google.com with SMTP id j1so33748419oih.3 for ; Wed, 01 Jun 2016 08:47:33 -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; bh=o0HD9MPx7SyrODcw8L54qoYepMbsVs7tenOJYxEbrUI=; b=pzubMIG1x8rprXEZ6bMmXgVKqWFK6f+HsMzBiaMLFilQW2n1hdEcCg5dLMPXF5oZbh 6x+wfz+lU3SikO08V3YZLgmeTmLGcDIJKxA9NoVEksCck3L24ggyJEkztMHLpEqOKoRt NUAIc+YnlUSWrUXLx1fry2C116iAIPxZROTasLhzexSHP/VXSddkPG9D4/SNkHAWW7+N fd2lqhRf75l0c1iOP00MZuTEg0YEBTobLq0Va7ESS2yXdOCgGkIEP6wxhoQ6PE0jykfQ GY5iFqroX3Oa06/fEsSaUQRY1eYtFWvYPYd9z76V9c+h32J5+8Dv95mrNLbvwkrxaDeA ZuAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:date :message-id:subject:from:to:cc; bh=o0HD9MPx7SyrODcw8L54qoYepMbsVs7tenOJYxEbrUI=; b=Y1NMKK5YWqx91imo1zFL8Qsmx3UnSiuYIhWrrFn5XkYhUvUh9hsdpaEFuUMcFPh1XO LZv6yc+STzZTWZrnbdkqL9mELf0g3Bm4Qcv/vbAXogOWAoi6hm5l3o8rA/LpRONDFAIt G6kEwtBwPlktqd77B6EF8ZU+iz7b6DZXa+UMwKNm3q8C0qzW4HHu+h0GZSlCeX2nmCOH tccrIvQYSW5OoW7TXHIWNpmhhOJvbpLNshoJxxHpbA74oCvtS9yVRJe8Og4VtmoA821R 7TQJu1kWO2R2mcVe184nQZyLgEx6DPCgq+0i/Jojs1wRZuUpvbCpvsJJKkaxgpFRZ4Om 7O6g== X-Gm-Message-State: ALyK8tKxijrUWxytf7Yc/Na3koTuJnSaf7fnYRDth7W+jcNbJVV71XnyhpSYTsjvStSpln/eGQBSTCvQ9x0btQ== MIME-Version: 1.0 X-Received: by 10.202.1.86 with SMTP id 83mr24018592oib.148.1464796050536; Wed, 01 Jun 2016 08:47:30 -0700 (PDT) Received: by 10.157.7.228 with HTTP; Wed, 1 Jun 2016 08:47:30 -0700 (PDT) In-Reply-To: References: Date: Wed, 1 Jun 2016 09:47:30 -0600 Message-ID: To: Matt Fonda Cc: Jesse Schalken , PHP internals Content-Type: multipart/alternative; boundary=001a1137dd4842c3cb053439682f Subject: Re: [PHP-DEV] Set object properties inline From: derokorian@gmail.com (Ryan Pallas) --001a1137dd4842c3cb053439682f Content-Type: text/plain; charset=UTF-8 On Wed, Jun 1, 2016 at 9:37 AM, Matt Fonda wrote: > > > Hi Jesse, > > It's fairly straightforward to implement a function that does this in > userland, for example something like the following: > > function f($fqcn, $args) { > $instance = new $fqcn; > foreach ($args as $key => $value) { > $instance->$key = $value; > } > return $instance; > } > ... > $this->fooMethod( > $arg1, > $arg2, > f('FooParams', [ > 'prop1' => ..., > 'prop2' => ..., > 'prop3' => f('Obj1', [ > 'prop1' => ..., > 'prop2' => ..., > ], > ]) > ); > > You may also use the approach Peter suggested. As such, I don't think > introducing a new syntax for it is necessary. > I disagree here. This lets you add dynamic properties accidentally (by putting too many entries in the array or misspelling a property as a key), this method does not let IDEs help you with the construction of the array, or even what's valid for each value in that array and doesn't provide any language level protection against misspelled properties. Of course, for the last point, I'm assuming that this idea works like the following: class Foo { public $prop1; } new Foo () { porp1 = 'foo' // undefined property error of some sort }; > Best, > --Matt > --001a1137dd4842c3cb053439682f--