-
Notifications
You must be signed in to change notification settings - Fork 36
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed return by reference to allow modification
- Loading branch information
Showing
1 changed file
with
2 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
91512cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Although I have no idea if this is an external API, but I'd use objects instead of arrays if you want to allow modifications of the returned value.
Using arrays is error prone, since it's not enough to specify the method to return a reference, but you'll have to assign the return value by reference as well. I think this is something you might easily overlook. But again, I'm not familiar with the PHPCR yet, so I don't know if any end-user is going to use this method :)
91512cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, it's kinda dangerous, but not sure either how useful this thing is at this point.
91512cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
maybe we could add this warning into the doc comment so people who read the comment get the hint. having a list object or something sounds like too much weight to me.
91512cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I completely agree. I suggest using
ArrayObject
internally.[edit] On second thought: It's a language feature, why not use it? It gives you the possibility to decide whether you want to receive a reference or not. Although I don't know whether the requirement of the ampersand has changed in recent PHP versions or not (i.e., leading to confusion). But there is not much to refactor for using an object.. and can easily be done at a later point if required.
91512cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The problem is if you start using an object then you should not return a reference anymore. That's PHP4 style and it sucks. But arrays are not objects and need to be referenced explicitly otherwise they're just copied around. If the API says it has to return a mutable list, I think that should be an object. And ArrayObject seems like a good fit.
@rndstr: The reference feature in PHP just confuses most people because it's barely ever used so I don't think it's a good idea to make use of that if we can avoid it easily.
91512cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after reading up the ArrayObject thing: we could define the interface saying it returns something implementing Traversable , ArrayAccess and Countable. then jackalope can just use ArrayObject, but if at some point we realize for performance or whatever we want something else, its always possible. rndstr, can you change it that way? and write some tests that check if it actually works :-)
91512cc
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I already wrote the tests, refactoring to use ArrayObject now :)