Hello all,
I appreciate all the hard work you guys are doing to improve the PHP experience for all of us and know you are busy with some 'large' proposals (Cache/Request etc) but I hope this would be interesting for you guys. If not (or this has already been proposed/rejected) or this is the wrong place to ask, my apologies.
Proposal: Arrayable Interface
TLDR: I propose creating 1 interface (Psr\Arrayable) with 1 method (toArray()) which returns the array value of the object.
I like the idea, although the name itself could use some work, especially if we introduce other formats (see below).
--
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+unsubscribe@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/54568D3C.1090800%40googlemail.com.
My main concern would be identifying the benefit and then explaining how it improves on method_exists(). An interface with a single method will always face that one ;).It's self evident that many classes use toArray() for the obvious purpose, but that is not in and of itself a justification for an interface out of context. I can't think of any instances off hand where it would have an impact on interoperability, good or ill.Paddy
all "toFooBar()" methods have a inherent/common misconception: the lack of context. They are *only* usefull in a specific context and should not be generalized (as context-free interface). Establish a fixed context will interfere with other valid usecases.
cryptocompress
An EnumerableInterface would be more like http://php.net/manual/en/class.arrayaccess.php probably? That is not what I meant. I just meant a simple method to get a plain array, as clean as possible.
My main concern would be identifying the benefit and then explaining how it improves on method_exists(). An interface with a single method will always face that one ;).
--
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 view this discussion on the web visit https://groups.google.com/d/msgid/php-fig/2d52eb69-67cb-4229-88a1-2f7dd344ffa8%40googlegroups.com.
If toArray os standardized and then in the future __toArray becomes available we'll just create confusion.
I'm not sure if this goes against best practices, but optional parameters do seem to work: http://3v4l.org/evf92
I'm not sure what you mean with the __toString() reference. __toString() is an internal method and therefore doesn't need any interface. No method for casting to an array is defined, so an Interface could be use the explicitly define the behaviour of this method.
And remember, I'm not suggesting that we all stop what we are doing now and go and add toArray() methods on everything or that this is a best practice.I merely noticed that a lot of projects (also from the FIG) are using toArray() or similar methods, and even the same interfaces. And it does come up as a question/proposal regularly.
And because of the aims of the FIG ('The idea behind the group is for project representatives to talk about the commonalities between our projects and find ways we can work together.') it might be useful to create this simple interface for this purpose.
But that is up to the members of the FIG, as there would first need to be 2 sponsors and then an entrance vote to see if anyone cares at all.
Example: I have a contract with the fruiterer to deliver 100 apples each week. Now i call and ask for 100 pears instead, without changing the contract. May contractor deliver me bananas? ;)I'm not sure if this goes against best practices, but optional parameters do seem to work: http://3v4l.org/evf92
You can implement the "print_r() / dump to string" direct on Item and ItemCollection within __toString() as this was the only purpose of whole example.I'm not sure what you mean with the __toString() reference. __toString() is an internal method and therefore doesn't need any interface. No method for casting to an array is defined, so an Interface could be use the explicitly define the behaviour of this method.