Why might my PHP log file not entirely be text?

I’m trying to debug a plugin-bloated WordPress installation; so I’ve added a very simple homebrew logger that records all the callbacks, which are basically listed in a single, ultimately 250+ row multidimensional array in WordPress (I can’t use print_r() because I need to catch them right before they are called).

My logger line is $logger->log("t" . $callback . "n");

Read More

The logger produces a dandy text file in normal situations, but at two points during this particular task it is adding something which causes my log file to no longer be encoded properly. Gedit (I’m on Ubuntu) won’t open the file, claiming to not understand the encoding. In vim, the culprit corrupt callback (which I could not find in the debugger, looking at the array) is about in the middle and printed as ^@lambda_546 and at the end of file there’s this cute guy ^M. The ^M and ^@ are blue in my vim, which has no color theme set for .txt files. I don’t know what it means.

I tried adding an is_string($callback) condition, but I get the same results.

Any ideas?

Related posts

Leave a Reply

3 comments

  1. ^@ is a NUL character () and ^M is a CR (r). No idea why they’re being generated though. You’d have to muck through the source and database to find out. geany should be able to open the file easily enough though.

  2. Mystery over. One of the callbacks was an anonymous function. Investigating the PHP create_function documentation, I saw that a commenter had noted that the created function has a name like so: chr(0) . lambda_n. Thanks PHP.

    As for the r. Well, that is more embarrassing. My logger reused some older code that I previously written which did end lines in rn.