neo4jphp icon indicating copy to clipboard operation
neo4jphp copied to clipboard

Verify if offset exists

Open marcelojeff opened this issue 11 years ago • 3 comments

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!

marcelojeff avatar Nov 15 '13 16:11 marcelojeff

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.

jadell avatar Nov 15 '13 20:11 jadell

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.

jadell avatar Nov 17 '13 03:11 jadell

Nice! I'll work on this.

marcelojeff avatar Nov 18 '13 12:11 marcelojeff