News for hackers. Stuff that matters.
Re:Making a Go program 70% faster with a one character change by datalopers on Monday November 14, 2022 @01:59PM (#33599066)
That's not technically correct with regards to PHP. Your statement that any changes to $arr1 or $arr2 only impact the one in question, however, is accurate. If no changes are made they still refer to the same data in memory. It's copy-on-write semantics.

$arr1 = [1,2,3]; // $arr1 is a pointer to a zval array [1,2,3] and refcount:1

$arr2 = $arr1; // $arr1 and $arr2 are pointers to the same zval array but incremented refcount to 2.

$arr2[] = 4; // at this point, $arr2 creates a new zval array, copies over the data from the first, sets the recount to 1, and appends int(4). The [1,2,3] array has its refcount decremented to 1 as it's still referenced by $arr1.

[1] http://hengrui-li.blogspot.com/2011/08/php-copy-on-write-how...

Re:Making a Go program 70% faster with a one character change by TheRealPomax on Monday November 14, 2022 @02:26PM (#33599525)
true, good point.
Re:Making a Go program 70% faster with a one character change by johannes1234321 on Monday November 14, 2022 @02:47PM (#33599867)
Actually that is outdated since at least PHP 7. In modern PHP the engine uses copy on write only for "larger" things, but "small" things like integers or booleans live on the stack and are copied around, avoiding heap allocations etc.
Re:Making a Go program 70% faster with a one character change by morelisp on Monday November 14, 2022 @03:14PM (#33600306)
This isn't semantics, though, but implementation. As far as I'm aware there's no way to "observe" the copy short of digging into runtime debugging tools, so I think it's still fair to say the language has pass-by-value semantics. In C++ we still refer to things returned-by-value as returned by value despite the reality of NRVO, etc.
Re:Making a Go program 70% faster with a one character change by masklinn on Tuesday November 15, 2022 @03:01AM (#33606515)
> It's copy-on-write semantics.

CoW is not semantics, it’s a way of implementing value semantics which avoids unnecessary defensive copies.