Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89263 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 86377 invoked from network); 17 Nov 2015 11:19:52 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Nov 2015 11:19:52 -0000 Authentication-Results: pb1.pair.com header.from=t.carnage@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=t.carnage@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.54 as permitted sender) X-PHP-List-Original-Sender: t.carnage@gmail.com X-Host-Fingerprint: 74.125.82.54 mail-wm0-f54.google.com Received: from [74.125.82.54] ([74.125.82.54:35604] helo=mail-wm0-f54.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 44/B3-57591-65D0B465 for ; Tue, 17 Nov 2015 06:19:50 -0500 Received: by wmdw130 with SMTP id w130so150149007wmd.0 for ; Tue, 17 Nov 2015 03:19:47 -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=dVhHk9ajTKCQ0d6mUO7ewt5vcw+ygHIgZSEktEqIdnA=; b=KPZHDK27NtIVh6+spe7HzTdh7HHr+S1K0GzMpe+OFgmvu0U/gl6EdIo1Z0ESLraiXE rCEfOuqBTGL8oYGTazuXyr0D0DkLwIwDrxI9S9+KRzFmbIPPs6xWzirk8c3g4AVmwm3d puV4vojrUm+r57m2LTQFvqVt8n79/q37lnkURwG8n8qvwcPGdGTFX7fMuTj5sy7wuSiW nk2xA6stZAbhKtvNAywzDVy3bojXwCFyiRQGdb60XS4AdItlwg9k2l9/qEhnHR5IhjWV 8kIwosaBLBx8PJP2n+nipYc52GwlXmZVsKPnJn+TiVwOMkjgnIBjT4Pt6J9ilMMkMRLv tVgg== MIME-Version: 1.0 X-Received: by 10.28.18.9 with SMTP id 9mr1951107wms.96.1447759187176; Tue, 17 Nov 2015 03:19:47 -0800 (PST) Received: by 10.27.130.149 with HTTP; Tue, 17 Nov 2015 03:19:47 -0800 (PST) In-Reply-To: <564B09A4.3050706@gmail.com> References: <564A547C.9060504@garfieldtech.com> <564A629C.9040709@rochette.cc> <564A69C1.5080208@garfieldtech.com> <2D.66.34372.2A78A465@pb1.pair.com> <564B09A4.3050706@gmail.com> Date: Tue, 17 Nov 2015 11:19:47 +0000 Message-ID: To: Rowan Collins Cc: PHP internals Content-Type: multipart/alternative; boundary=001a1145bd101272560524bab458 Subject: Re: [PHP-DEV] Immutable modifier From: t.carnage@gmail.com (Chris Riley) --001a1145bd101272560524bab458 Content-Type: text/plain; charset=UTF-8 On 17 November 2015 at 11:04, Rowan Collins wrote: > Hi Andrea, > > Andrea Faulds wrote on 17/11/2015 01:47: > >> Larry Garfield wrote: >> >>> The "everything in the constructor" is the problem. That results in, >>> essentially, an obscenely long function call that just happens to be >>> named __construct(). If I wanted something that obscure and hard to >>> work with I'd just use anonymous arrays. :-) >>> >> >> Huh? >> >> "with" methods and __construct are not exclusive. In fact, you could have >> a private constructor and only have "with" methods. Only allowing >> assignment to properties in the constructor doesn't prevent having a nice >> API: have your methods call the constructor. >> >> I don't see what you're getting at here. >> >> > Making the "with" methods wrap the constructor tidies the public API, but > that (private) constructor needs to be just as complex as Larry said > earlier - you've got to manually extract all the properties of one > instance, and pass them as parameters to the other. Or, you could copy them > one by one inside the body of the constructor, which comes to the same > thing - lots of boilerplate. > > If you look at the PSR-7 implementation I linked to earlier [1], there's > no such boilerplate, just a single call to "clone $this", and PHP does it > all for you. But that doesn't work with a simplistic definition of > immutable like "mutable in constructor" or "mutable until non-null"; you > need to be able to "freeze" an instance once you've set it up, or have > privileged (private) methods which are allowed to mutate the properties. > > [1] https://github.com/guzzle/psr7/blob/master/src/Request.php#L101 > > Regards, > -- > Rowan Collins > [IMSoP] > > -- > PHP Internals - PHP Runtime Development Mailing List > To unsubscribe, visit: http://www.php.net/unsub.php > > Could clone take an array parameter of immutable property overrides? $copied = clone ($immutable, ['foo' => 'bar']); --001a1145bd101272560524bab458--