Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:81540 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20503 invoked from network); 1 Feb 2015 19:17:15 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 1 Feb 2015 19:17:15 -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 209.85.212.176 as permitted sender) X-PHP-List-Original-Sender: rowan.collins@gmail.com X-Host-Fingerprint: 209.85.212.176 mail-wi0-f176.google.com Received: from [209.85.212.176] ([209.85.212.176:51531] helo=mail-wi0-f176.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 99/93-33325-ABB7EC45 for ; Sun, 01 Feb 2015 14:17:15 -0500 Received: by mail-wi0-f176.google.com with SMTP id bs8so12598958wib.3 for ; Sun, 01 Feb 2015 11:17:11 -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:subject:references :in-reply-to:content-type:content-transfer-encoding; bh=eSVLajsLEncJ7NJB5en03NeSpW49VKvE8prm+SgrV20=; b=aIFFF043DA6vra1WVui4HhJL7HSDrAg/XbruNb1tkwTsjj/UuIB37dWzf9pV6+gWr/ Soc2rdJ9z4bhnqWHowCgRXUgpdhJ7QpSnE64FOtYoVTFmEXhsPYCkjZyAoeY8/B7GkzG bazFUHm0KcfJr4m22AN33NNGSGXc6GtQA4zv11v6H8tc/ZyZVUIOiWPiDC+CHMVAzt5x xXMCXSK96l8MvgoexywWXsI6T6Zg0x4qvNLIGD44Se1xhF1xG6vs1MiQ3YPtA0q+tkiG hkHRCsc4nyF+Muv4XaKKvHU2o+8pdxyTgZ04RclPqeoI9gC9AiagI6F/xO7PrZSGXacF BF6A== X-Received: by 10.194.5.37 with SMTP id p5mr36904069wjp.20.1422818230943; Sun, 01 Feb 2015 11:17:10 -0800 (PST) Received: from [192.168.0.2] (cpc68956-brig15-2-0-cust215.3-3.cable.virginm.net. [82.6.24.216]) by mx.google.com with ESMTPSA id d6sm16475775wic.1.2015.02.01.11.17.10 for (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Sun, 01 Feb 2015 11:17:10 -0800 (PST) Message-ID: <54CE7B9D.5000501@gmail.com> Date: Sun, 01 Feb 2015 19:16:45 +0000 User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:31.0) Gecko/20100101 Thunderbird/31.4.0 MIME-Version: 1.0 To: internals@lists.php.net References: <54CBC804.7050706@gmail.com> <54CD7668.30301@garfieldtech.com> <61B0AAF8-9A3E-4889-917E-42AA48D946FA@ajf.me> In-Reply-To: <61B0AAF8-9A3E-4889-917E-42AA48D946FA@ajf.me> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Subject: Re: [PHP-DEV] [RFC] Immutable variables and objects From: rowan.collins@gmail.com (Rowan Collins) On 01/02/2015 01:01, Andrea Faulds wrote: > Given that PHP is dynamic, not compiled, and function calls can have side effects, though, this would be difficult to enforce. You’d need to check that all calls made within the function do not have any side effects on that value… > > I’m not sure how workable this is. If you can implement copy-on-write, you can implement immutability, and vice versa. However, any context where its possible to mix mutable and immutable (or mutable-reference and copy-on-write) would get confusing very quickly, I think. Consider some possible behaviours of this set of objects: $a->b = $b; $a2 = $a; $a2->b->value = 42; If every object is immutable or copy-on-write, this is easy to reason about: $b and $a->b remain the same, while $a2->b is created as a new clone; in doing so, $a is separated from $a2 to reference this new copy. But what if $a/$a2 are immutable, or copy-on-write, but $b is not - do $b, $a->b and $a2->b all reflect the change, with no error? That would certainly make no sense for const parameters, and would be a massive gotcha for "value objects" defined as such at the class (rather than instance) level. Regards, -- Rowan Collins [IMSoP]