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]


--
PHP Internals - PHP Runtime Development Mailing List
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to