3 ms·
> You just pass by value, return by value everywhere, all day long This is actually how I've been writing PHP programs for years, passing arrays around like I
by TOGoS 3y ago
> You just pass by value, return by value everywhere, all day long
This is actually how I've been writing PHP programs for years, passing arrays around like I just don't care.[3]
I think the PHP interpreter is smart enough to actually only copy-on-write, but I admit I've never profiled these programs. But anecdotally, I've done some pretty complex stuff[1] this way and it never caused noticeable performance problems.
[1] Complex as in 'wow I sure am making the computer process a lot of data, parse some DSL character-by-character, dynamically generate SQL and massage the results into some arbitrary structure for EACH PAGE LOAD, geez'. Not as in 'print hello world, but using Laravel', which somehow manages to be about 30x as computationally expensive[2].
[2] quip about how 'web artisans' spend the time between page loads brewing coffee using their CPU as a heating source while thinking deep thoughts. But I digress.
[3] Back in the PHP 4 days, objects, too, acted as if stored in variables rather than just pointed-to by them. Not that anyone expected language design excellence from Rasmus et al, but strikes me as a missed opportunity when they changed object variables to having reference semantics to have 'value, variable reference, or pointer-to-value' be a property of variables orthogonal to the type of value they store/reference. e.g.
$a = $b; // Copy $b's value into $a
$a = &$b; // $a and $b are now the same variable
$a = *$b; // $a points to the same object as $b, but unlike $a = &$b, the variables themselves are not linked