neo4jphp
neo4jphp copied to clipboard
Verify if offset exists
When i was trying to get the current Row from a ResultSet ($query->getResultSet()->current();
) that can be empty, i'd got the follow error:
Notice: Undefined offset: 0 in vendor/everyman/neo4jphp/lib/Everyman/Neo4j/Query/ResultSet.php on line 54
So, i'm suggesting to verify the offset existence, then return null if it not exists.
Thanks in advance, and sorry for my english!
Use count($resultSet)
to determine if the result set is empty or not.
The ResultSet and Row classes are meant to act like PHP arrays as much as possible. The warning you are seeing is the same one you would get if trying to access an array key that didn't exist. I don't think it is a good idea to hide those semantics. You shouldn't be calling current
on the ResultSet; that is merely an implementation method for the Iterator
interface.
If you think null is the proper response to asking for a non-existent row, that is fine (that does mirror the array semantics), but a notice should still be throw using trigger_error
. Also, please write a test for the behavior. The Query\Row
class should also follow the same behavior.
Nice! I'll work on this.