Re: [PHP-DEV] A little syntactic sugar on array_* function calls?

This is only part of a thread. view whole thread
  114616
May 26, 2021 11:54 office.hamzaahmad@gmail.com (Hamza Ahmad)
> should array object be passed by value or by reference? > If we are to have array object, will it be exceptional?
By value. Because array is a data type, we are talking about making it behave like object. In JavaScript, Arrays, Strings, and Numbers are objects; they have their respective properties and methods. Still, when they are passed to a function or a method call, they are passed by value, not by reference. We should pass arrays by value because it will let a function or a method modify it without changing the original array. If we make it a regular object, it will be a bc break. So, whenever a callable modifies an array, it will modify a variable out of its scope. I am talking about attaching some methods and properties to array (or largely, the string, int and float) type. In your manner, an exceptional array object that is passed by value, Which will have "key_first", "key_last", "keys", "values", "length", "type" (if PHP later introduces typed arrays), and "is_list" as properties, and "reverse", "flip", "map", "filter", "walk" and so on as methods. Such methods will be performed on a value, not a variable. In other words: `[1,2,3,4,5,6,7,8,9,0]->print();` will work. This way, it does not matter whether one modifies a variable or a value. According to the implementation of Nikita's extension, there will be functions attached to each method of a type. To remove this limitation, what if array is an internal array object? To make my previous statement regarding making array_* functions as method aliases for array->* methods, I give the example of mysqli. It has both ways of interaction, object-oriented and procedural. So, why not this with arrays? Regards On 5/26/21, Mike Schinkel <mike@newclarity.net> wrote:
> > >> On May 25, 2021, at 6:28 PM, Iván Arias <txigreman@hotmail.com> wrote: >> >> Hi all, >> >> It sounds like scalar objects by Nikita: >> https://github.com/nikic/scalar_objects > > Yes, but Nikita wrote this note about technical limitations at the bottom of > the repo README: > > Due to technical limitations, it is not possible to create mutable APIs for > primitive types. Modifying $self within the methods is not possible (or > rather, will have no effect, as you'd just be changing a copy). > > Does that mean that the scope of Nikita's proof-of-concept could not modify > $self, or that it is simply not possible to modify $self given limitations > inherent in PHP? > > Further, does that only apply to scalars, or might possible arrays could be > different? > > -Mike