-
Notifications
You must be signed in to change notification settings - Fork 79
Support for objects? #2
Comments
I'm trying to ensure that this remains consistent with the PHP implementation. That said, I'll keep this open and see if I can get this proposed and implemented in the core and HHVM, and then I'll add it here. :-) |
I just noticed PHP 7 will support array of objects :-) (implemented in php/php-src@3bf012a) |
Interesting. So, if I back-port it into this library, the object support will only work for Thoughts? |
Create a feature override branch that does override and implements newer behaviors there and use that to create a secondary script perhaps array_column_7. I know a single script is probably prefered but you just can not override and default to core at the same time. I feel it best used as a plug and play type setup(no configs). You have the script it works just choose your preference array_column or array_column_7 ... |
I'd probably namespace it, rather than use |
Personally I had added an Your proposals sound good too, but I can think of some caveats. For example, you could forget to use the namespaced function and it would go unnoticed, the code would work just fine until an object is encountered or you switch from PHP 7 to 5. |
I would suggest creating a new package "object_column", defining a function Once the user has moved to PHP 7 and doesn't plan to go back, he could simply replace |
And on second thought, -1 on the namespaced function proposal. I think it would be far too prone to forget the import and use the native function by mistake. |
Yeah. I'm not really sure the best approach here. This polyfill is for people using PHP 5.4 and earlier. If anyone is using 5.5 or 5.6, object support in this package won't help them, since they'll be using the native PHP function. I assume people are more likely to go from 5.3 and 5.4 to 5.6 before moving to 7.0, which will cause their applications to break, if they rely on this library with object support. |
That's precisely why I thought about creating a new package, bringing a separate function |
PHP 7.0 supports objects. Please update this package for those of us stuck on PHP < 7 or HHVM! |
Though as it turns out, this won't help us, because PHP/HHVM already defined |
Trying to provide compatibility to previous versions when the function changes drastically across versions in which it is implement is hard. |
It would be great if you could pass in an array of objects, and the index key provided merely accessed one of the properties to be used when re-indexing the array of objects.
I know that you can implement the ArrayAccess interface, but it's a bit tedious to do this for every object that you just want to be able to reindex an array of.
A simple check to see if
$row
is an object would be good. A more robust implementation might allow you to define a method call against a class as the index key e.g.array('Person', 'getID')
.Of course this would make it inconsistent with the actual PHP implementation, but it would make this more useful. Having to implement ArrayAccess marginally defeats the purpose of using the terse syntax of
array_column()
over the slightly more verbosearray_map()
The text was updated successfully, but these errors were encountered: