Last week Friday/Saturday I had the privilege to join PHPUnit Code Sprint. It was a rather small event with only six people, but the competence was huge.
I expected something like our FireGento hackathons, but due to the small group, we started with an introduction how PHPUnit was the last years and then Sebastian Bergmann started to introduce us to a couple of problems he brought with him. But as expected he didn’t make it to the second, because everyone was already thinking about how to solve the first and we started a lovely mob programming session.
And then we fell into a deep rabbit hole. I never heard of hrtime() but it is a method in PHP to get a time from the operating system. The assumption is, that the return value is monotonic, but for some reason there are people who somehow make the duration based on hrtime to take negative time ? As you might expect: This shouldn’t be the case, no one implemented a time machine – yet. We read the code. Again and again, thought about it but couldn’t explain why this happens – under the assumption that every hrtime() call returns at least the same (not unix) timestamp. As you can see on the ticket, even the reporters have a rough time to reproduce it, so we decided that obviously a negative duration doesn’t make sense and throwing an unreliable exception for whatever reason is not helpful as well, so we ignore negative durations and just return a duration of 0. That doesn’t make the nerd in all of us happy, but it makes the code work – and make it work is the most important thing.