Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81515 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 26461 invoked from network); 1 Feb 2015 02:10:01 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Feb 2015 02:10:01 -0000 Authentication-Results: pb1.pair.com smtp.mail=smalyshev@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=smalyshev@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.220.43 as permitted sender) X-PHP-List-Original-Sender: smalyshev@gmail.com X-Host-Fingerprint: 209.85.220.43 mail-pa0-f43.google.com Received: from [209.85.220.43] ([209.85.220.43:64758] helo=mail-pa0-f43.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id D0/6C-01632-7FA8DC45 for ; Sat, 31 Jan 2015 21:10:00 -0500 Received: by mail-pa0-f43.google.com with SMTP id eu11so67701566pac.2 for ; Sat, 31 Jan 2015 18:09:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=message-id:date:from:user-agent:mime-version:to:cc:subject :references:in-reply-to:content-type:content-transfer-encoding; bh=3T8R7IQQ/jnJGjJvOIrS7wL9ZJMaOqWx2f+n7e+LbdY=; b=A7LjgnWwe79yrIxFjgAjUErc6CCn9BG3bdB0FqgjIG4zJ7iTTxNzyxh3OuaG2yMwXx U00VEvoJT61Az22VM+cK4O/hlB2Rvh1fgII0xiegAodxFiPmgBjK1i+5b9c4FuqjaJvd blO3052gJmDEpnZRYpVONih8o7+E5hqdObHB9NTx/cbwGQrN001mayAC6whyDK8wq7Ra 3Y4IjyA4nYU/iG8uhCfaSC/AR6Kl5G+O4o8IytjkEKd7qxxo0lbqY0gONNng6a7ow19Q +zcf3qxy1NMvpyUGRcIhetWiAc/LuEdNDulNzdVgLVt3Lsp1rQOlQN0KYSsBgHSSOvdJ 5jgA== X-Received: by 10.67.8.2 with SMTP id dg2mr19968465pad.15.1422756596182; Sat, 31 Jan 2015 18:09:56 -0800 (PST) Received: from Stas-Air.local (108-66-6-48.lightspeed.sntcca.sbcglobal.net. [108.66.6.48]) by mx.google.com with ESMTPSA id fs1sm14843755pdb.16.2015.01.31.18.09.55 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sat, 31 Jan 2015 18:09:55 -0800 (PST) Message-ID: <54CD8AEE.2070407@gmail.com> Date: Sat, 31 Jan 2015 18:09:50 -0800 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.9; rv:31.0) Gecko/20100101 Thunderbird/31.3.0 MIME-Version: 1.0 To: Andrea Faulds CC: Larry Garfield , internals@lists.php.net References: <54CBC804.7050706@gmail.com> <54CD7668.30301@garfieldtech.com> <54CD7975.8040908@gmail.com> In-Reply-To: Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Immutable variables and objects From: smalyshev@gmail.com (Stanislav Malyshev) Hi! > Here, there’s no redundant objects made, but if you pass $a on, it’d > be automatically copied by PHP, so you don’t need to worry about it > being modified. I don't think it's a particularly good solution in this case, as in many cases (especially DI setups, many design patterns, etc.) the whole point of creating the object is to pass it around. Just pointlessly copying it out of fear somebody somewhere could modify it doesn't sound the best way. I'd rather just have a clear separation between mutating and non-mutating APIs, and instruct people to use the right ones in right situation - i.e. if you created the object or own it, use mutating ones, if you got object from outside and do not have full ownership of it, use non-mutating ones. > Would that make sense? It’s no different than how our existing value > types like scalars and arrays work. Scalars don't have this problem as, except for string offsets (IMHO not the best idea to have mutable strings too) scalars can not really be changed, just replaced with other scalars. But implementing value objects in PHP is not hard right now - if you don't provide any methods that allow changing state, you've got an immutable object. It's just not always what people using it would want, especially with something as complex as HTTP message. -- Stas Malyshev smalyshev@gmail.com