DEV Community

Discussion on: How Simple is too Simple to Test?

Collapse
 
scotthannen profile image
Scott Hannen

I was hesitant to mention it because I don't details of the language. I was just curious because I didn't know if you could compare the first and second elements without an exception if there were fewer than two elements. In .NET the check itself would throw an exception, so I'd check the number of elements first.

Thread Thread
 
bosepchuk profile image
Blaine Osepchuk • Edited

No worries. We're just talking. Bring up anything you like.

I swapped the if statements this morning in the actual code (not updated in the blog post). So the size check is now before the equality check.

If you turn up the warnings enough in PHP you'll get a notice about accessing a nonexistent array element but it won't throw an exception on its own.