I have spent an hour today debugging a weird issue: PHPUnit complained that it tried to call an undefined function PHPUnit\Framework\Assert\assertEquals():

Because right now I am working with custom PHP extensions, I suspected the worst: the code corrupted PHP’s internal memory somewhere, and at that it was lucky enough to damage only allocated memory.

Of course, tests with Valgrind did not show anything. When I commented out some tests, everything worked. I checked every function again and again but all in vain.

And then I looked at the function name again: PHPUnit\Framework\Assert\assertEquals(). assertEquals has turned into a function but it used to be a method (a public static method). Very interesting. I scrolled up the code to the test setUp() function and my eye caught this:

Eclipse in its infinite wisdom decided to alias PHPUnit\Framework\Assert\assertEquals() as strlen() and mb_strlen(). It did that automatically, and I missed that change.

That was a very cruel joke.

What have I learned from this experience?

  1. Automatic (especially when they are silent) code fixes are evil.
  2. git diff is your friend.
  3. Trust yourself more: not all bugs are your fault 🙂
Eclipse Can Break Your Code
Tagged on:         

Leave a Reply

Your email address will not be published. Required fields are marked *