Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:93694 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 5049 invoked from network); 1 Jun 2016 20:20:44 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Jun 2016 20:20:44 -0000 Authentication-Results: pb1.pair.com header.from=jesseschalken@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jesseschalken@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.214.42 as permitted sender) X-PHP-List-Original-Sender: jesseschalken@gmail.com X-Host-Fingerprint: 209.85.214.42 mail-it0-f42.google.com Received: from [209.85.214.42] ([209.85.214.42:35508] helo=mail-it0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id CD/07-63812-A934F475 for ; Wed, 01 Jun 2016 16:20:43 -0400 Received: by mail-it0-f42.google.com with SMTP id z189so92877609itg.0 for ; Wed, 01 Jun 2016 13:20:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:date:message-id:subject :from:to:cc; bh=J1jI+59qqwip6pt3fQMtd5DR9fTHGVhkKDJmHJcJInU=; b=mbqfL+jMaOwZlpgk5fsVPWUrQtuWe/PfzhM3TEZty/7Ru59LWaAZoMJLZO7VRzPLyi AfWK52cD1Vw8VaPAYPEuPpbKTlQ9NfCjoosxDC22VflPpB2054+8V7Zzk3wa7db2zASD 1S5Uvzl1/3293EbU2QSmX/WRaSgh4EffeuDKFzNOqHINs6li20FcjJD8s2bQncjICK9V gdoq33wCpKxqh2ZKxUD9csGuamDjwMYdY2mFg/AaDfvyNwULYaA8qGhvnlp0h556QWux POBtp0SSgZnbSAvQPU0dchthOyjzErdYYNqxY+WtEuA2P51Af6ndEZLLvAL+ozP+kQBD 0j2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:cc; bh=J1jI+59qqwip6pt3fQMtd5DR9fTHGVhkKDJmHJcJInU=; b=R+ZQZorSPUznhOJr1SLl07afTpiWaJEFj717DtRocDq1H4r9P3BHIM+sMtp/xXFvNb EFt8bVh1wU+kQHx+gGv0a02ySYrDRsBunx5EPhjYxce/wo8dCvXlwW4TLRYGSKq6t2d1 AdXgRIv3/BYBk1+Lund1e/AHMAlXD8Jlvjj27Zjj7D1Lx9F3I31p0tl4PUn38chhDbcx Q427iKm4Dulb+L4NdQv+IaC8qPtS53KOY5Dv4eBAXYjvFw3Z7wUzCgIaZ1hsveYIIktX ulVgnrK8HlEw4EtLFonfC+JuA3qT7bGyFWmgGBfBxjfbyQ1wShulZrPEgARaSuIrGtE6 qznw== X-Gm-Message-State: ALyK8tI04DK9k7RgkDghTsQtdHVJZb+JZAHtHt4w+W7VOdJ4PTwJHdctDS6Yrur42liq4t0JtBl7r4LfXTnK3Q== MIME-Version: 1.0 X-Received: by 10.36.112.81 with SMTP id f78mr8789090itc.32.1464812440512; Wed, 01 Jun 2016 13:20:40 -0700 (PDT) Sender: jesseschalken@gmail.com Received: by 10.79.111.208 with HTTP; Wed, 1 Jun 2016 13:20:40 -0700 (PDT) In-Reply-To: References: Date: Thu, 2 Jun 2016 06:20:40 +1000 X-Google-Sender-Auth: rKvud3G2QZmLSMTBXU0ak7s0F_o Message-ID: To: Peter Cowburn Cc: PHP internals Content-Type: multipart/alternative; boundary=001a113f6c642df0e305343d391d Subject: Re: [PHP-DEV] Set object properties inline From: me@jesseschalken.com (Jesse Schalken) --001a113f6c642df0e305343d391d Content-Type: text/plain; charset=UTF-8 On Wed, Jun 1, 2016 at 7:49 PM, Peter Cowburn wrote: > > While it's not as concise as your example, anonymous classes can do this > already after a fashion. > > $this->fooMethod( > $arg1, > $arg2, > new class() extends FooParams { > // Constructor because prop3's value isn't a constant expression > function __construct() { > $this->prop1 = '...'; > $this->prop2 = '...'; > $this->prop3 = new class() extends Obj1 { > public $prop1 = '...'; > public $prop2 = '...'; > }; > } > } > ); > > While that does avoid the temporary variable it seems more verbose than the temporary variable was to start with, even more so if you want to use variables from the outer context, since you have to thread them through the constructor. It also seems excessive adding a whole new (anonymous) class to the runtime just to avoid a temporary variable, but maybe that doesn't matter. --001a113f6c642df0e305343d391d--