4 ms·
Not to mention a couple of other things I hate about PHP arrays: 1) They don't extend stdClass so they aren't technically objects-- they're a different data ty
by edtechre 15y ago
Not to mention a couple of other things I hate about PHP arrays:
1) They don't extend stdClass so they aren't technically objects-- they're a different data type completely (WTF?)
2) Arrays are passed by value and not reference by default. Double WTF. So passing an array to a method call without the & reference operator is inefficient and prone to bugs as noobs don't expect the immutable behavior.
- edtechre 15y agoI could be wrong about the inefficiency, maybe arrays in PHP are implemented as "copy on write". But seeing how PHP is such a mess of a language, I somehow doubt it...
- pilif 15y agoThey ARE implemented as COW. It's discouraged to use explicit reference passing if you don't want to alter the array as PHP has to do a slight bit more work if you pass a reference. I think copy on write was added in the 5.1 timeframe (around 2005)
- edtechre 15y agoThanks for the info. I do think the default should have been pass by reference though, like with objects since PHP5.
- pilif 15y agoArrays (and everything else) should be objects. That would also solve the pass-by-reference issue and would clean up the global namespace that's littered with array_* functions.
- deleted 15y ago[deleted]
- wvenable 15y agoCopy-on-write has been around a lot longer than 5.1. I'd venture to say PHP 4 but someone will likely reply and say it was even earlier.