plain PHP arrays can not be transparently extended / instrumented in PHP code, which is necessary for a lot of advanced ORM features.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/php-fig/-/BYSzYkxLwvQJ.
For more options, visit https://groups.google.com/groups/opt_out.
I've always understood the rationale behind custom collections but never found out any good way of making them feel really native. OOP-wise everything seems fine but really useful functions like array_map or array_merge_recursive don't work.
Regarding the difference between Collection and Map and its practicabilityfor PHP, I'm really not sure. We know for example that SplFixedArray is faster than an usual array 'cause the engine ensures that, but a custom SplFixedArray written in PHP rather than C would probably be slower than a normal one. Mostly these different data structures are built for performance, not by their inherent interface limitations (for example, the recently added TypedArrays in JavaScript).That's the main difference between arrays and ArrayObject-like structures and it's huge, 'cause we can always getArrayCopy() to go native but then performance gets a major hit.Since Java was mentioned as an example, perhaps libraries like underscore.js could be considered as well for this. The purpouse is the same (make easy to play with sets and data structures), but in another paradigm (functional programming, which PHP also supports).
Another difference is that ArrayObjects have their object hashes and standard arrays don't, making ArrayObjects easier to work with algorithms that need object references instead of copying between scopes.
Also, speaking of SplFixedArray, how do we relate these custom collections with the SPL data structures?
You're proposing a distinction between two strucures. On Java, they're distinct mostly for performance requirements. Doctrine implemented so it can have strong object references to an extensibe generic object. These are use cases for these structures, what is the use case for the interop distinction between a Map and a Collection?
I love chaining, but that's only syntax.
I still don't see how separating Map and Collection would improve interoperability instead of making it harder.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/php-fig/-/TVwU6Y1W1hYJ.
I still don't see how separating Map and Collection would improve interoperability instead of making it harder.I think one reason to separate Collection and Map is their methods.
As I said, with PHP arrays the difference between a Collection and a Map is very small:
- Collection: $array[] = 'value'; $value = $array[];
- Map: $array['key'] = 'value'; $value = $array['key'];
But with OOP, that's another problem. Look and those differences:
- Collection
- add($value)
- contains($value)
- remove($value)
- Map
- set($key, $value)
- get($key)
- contains($key)
- remove($key)
These are the main features of a Collection and a Map, and they are really different (and not only in naming).
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/php-fig/-/TVwU6Y1W1hYJ.
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msg/php-fig/-/SrZnsUKBFnAJ.
You don't need to hint on that specific granularity (specially in a language that has type juggling). When you want a "month" you would probably hint for the superset, a DateTime. Why not hint for "array" or "ArrayObject"?
Why would someone need an object that absolutely cannot be Traversable while still must have ArrayAccess? (that's not rethorical!).
Unfortunately, PHP has some gotchas. A primitive array is not instance of Traversable and there is no common single interface for most array-like objects. There is no way to avoid this, it's mostly in the core of the language (since primitives and classes are two different typing systems in PHP) and there is no way for fig to "fix this".
You can just ignore the Travesibleness or ArrayAccessness of the object and use the interface you want, just like sometimes I only use the month of a DateTime object and still want the goodies from having it encapsulated.
This doesn't make sense to standardize datastructures imho, they should be optimized for their use case
not follow some arbitrary API.
For Doctrine we are not sure if we want to heavily break BC in the next eversion of collectoins, when we might introduce Lists, Sets and/or maybe even think about immutabliity of collections.
This doesn't make sense to standardize datastructures imho, they should be optimized for their use case, not follow some arbitrary API.
For Doctrine we are not sure if we want to heavily break BC in the next eversion of collectoins, when we might introduce Lists, Sets and/or maybe even think about immutabliity of collections.
How would that help interoperability? And why not just hint on the one of those you care about?
There is a piece missing here that is not connecting.
On Tue, Apr 21, 2015 at 2:22 PM, Christopher Pitt <cgp...@gmail.com> wrote:
I think this would be awesome. Any way I can help...
--
You received this message because you are subscribed to the Google Groups "PHP Framework Interoperability Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-fig+u...@googlegroups.com.
To post to this group, send email to php...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/c0a59769-b004-4939-a438-93025cf15fff%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
To view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/1429712337049.6b6c397a%40Nodemailer.
Hi everyone,Following a discussion on Github, I am bringing the subject to the ML: proposing a standard for Collections.Please note I am not a PHP-FIG member.Why?There is no Collection object or interface in PHP. Today, some libraries or frameworks make use of such a concept instead of a PHP array, for several reasons.The main example I have worked with is Doctrine, which introduces a Collection interface and several implementations. Quoting from the docs:plain PHP arrays can not be transparently extended / instrumented in PHP code, which is necessary for a lot of advanced ORM features.The Doctrine collection provides useful features in a OO way (like map, filter, forAll with closures), so that is useful for the user. But mainly, Doctrine proposes 2 implementations of the collection: a "simple" ArrayCollection, and a "PersistentCollection" that allows lazy loading, Criteria filtering directly using DB queries, etc. Thinks that would be difficult to implement with PHP arrays.I have not worked with Propel, but it seems there is a similar object: PropelCollection. I am sure I am missing other frameworks/libraries with a Collection interface, so feel free to complete the list of usages.So the idea would be to enable users or frameworks to make use of such objects without tying themselves to a particular implementation (by implementation I mean "implementation of a Collection interface", yeah bad choice of words).How?Before jumping into code, that would be interesting to properly understand all possible uses of such objects (so please speak if you use/propose collections in your libraries).There is also the question of "what is a collection?"I find interesting looking at what Java offers (only top interfaces):
- Collection: A group of objects. No assumptions are made about the order of the collection (if any) or whether it can contain duplicate elements.
- List: Extends Collection. Ordered collection
- Set: Extends Collection. No duplicate elements permitted. May or may not be ordered.
- Queue: Extends Collection.
- Map: A mapping from keys to values. Each key can map to one value.
As we can see, there is not "just" a Collection interface, because Map doesn't extend it. And that's understandable when you see how methods differ.In PHP, arrays can behave as Collection or as Map. That's mostly thanks to the array notation that makes that practical:
- $array[] = 'value';
- $array['key'] = 'value';
But is that possible to do it properly with objects?So the question is: should a PHP Collection behave as a Collection and as a Map, or should behaviors be separated?Put in other words: should the PSR provide a Collection interface, or a Collection and a Map interface?There are a lot of things to be discussed, but in order to not come empty handed, I have put together a gist inspired by Doctrine collections and Java Collection/Map: https://gist.github.com/mnapoli/5466043This gist can be discussed, forked, edited or also thrown away if useless.
I think we need a strong definition of what a Collection library does before we talk about it extensively. Ardent doesn't look like a Collections tool to me, it looks like a validation package.
Not a huge fan of this.Collections / arrays are *already* inter-changable without any libraries having to change their code at all. One library can simply pass the raw array underlying their collection to another library, which can then change the array back to a Collection object of its own choosing. Typically, the cost of moving from array to Collection and back again is negligible.
The big gap in PHP now isn't the collection per se, it's the incompatibility between arrays and iterators.