Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:89262 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 84142 invoked from network); 17 Nov 2015 11:04:20 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 17 Nov 2015 11:04:20 -0000 Authentication-Results: pb1.pair.com header.from=rowan.collins@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=rowan.collins@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.51 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 74.125.82.51 mail-wm0-f51.google.com Received: from [74.125.82.51] ([74.125.82.51:33308] helo=mail-wm0-f51.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id F6/43-57591-3B90B465 for ; Tue, 17 Nov 2015 06:04:19 -0500 Received: by wmec201 with SMTP id c201so221336146wme.0 for ; Tue, 17 Nov 2015 03:04:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=G3xLtf+0ETS9CTGixzIF+NvxCHoxfDV9Ext0Sev0tMQ=; b=jB3uNnE8mNDCeX2VtZ/8n2SkMTTrK53fW+pJk+ienM7ArIX2D9rDw0poi2I2aqGeKK RWUvqflexV3C6o8b6utY3Vy/GHGN38S8K3gvGoSRM7HVI12EDFfuaMmzHVmK4IgJLnc+ lMMpggWcM38JEY29Xj9/erZjlnU2a18ZFpgt1v62H7J7AcrTC2HnP4A3MpNPZcSUVJkl 2YTeCxLClcbPa5SqtYujIJdhBIOqzUGh8zj+bazn3NqyNOTB2artqVZvWaUcumplCTKH plEBHZlvD0gAXZUtLcSRTnyr7tOj2pi1ETQDOggSUPZCEvYG3MyUbXy4wooja9WQQbNM 3qOA== X-Received: by 10.28.93.145 with SMTP id r139mr1873228wmb.20.1447758256046; Tue, 17 Nov 2015 03:04:16 -0800 (PST) Received: from [192.168.0.157] ([93.188.182.58]) by smtp.googlemail.com with ESMTPSA id d66sm23310649wma.21.2015.11.17.03.04.15 for (version=TLSv1/SSLv3 cipher=OTHER); Tue, 17 Nov 2015 03:04:15 -0800 (PST) To: internals@lists.php.net References: <564A547C.9060504@garfieldtech.com> <564A629C.9040709@rochette.cc> <564A69C1.5080208@garfieldtech.com> <2D.66.34372.2A78A465@pb1.pair.com> Message-ID: <564B09A4.3050706@gmail.com> Date: Tue, 17 Nov 2015 11:04:04 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.3.0 MIME-Version: 1.0 In-Reply-To: <2D.66.34372.2A78A465@pb1.pair.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Immutable modifier From: rowan.collins@gmail.com (Rowan Collins) 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]