views:

63

answers:

3

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");

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?

+1  A: 

^@ is a NUL character (\0) 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.

Ignacio Vazquez-Abrams
I grabbed geany 0.81, and she complains "the file does not look like a text file or the file encoding is not supported".
Fletcher Moore
Weird. Is the NUL right at the beginning of the text file?
Ignacio Vazquez-Abrams
Also, hitting the `More Options`... "thing" at the bottom of the open dialog will allow you to manually select and encoding.
Ignacio Vazquez-Abrams
I checked the file with `od`. You are absolutely correct I've got a `\0` in the middle of my file and an `\r \n` capping it. How they got there is a mystery. Tomorrow I guess I'll have to investigate the problem areas line by line.
Fletcher Moore
A: 

Seems these cute guys are a result of your callback formatting for windows.

webbiedave
A: 

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 \r\n.

Fletcher Moore