Stupid PHP tricks

A

Anonymous

Guest
So I was just in the middle of coding (mostly playing with the wonderful patTemplate and patForms) and came up with this wonderful line of code:
PHP:
echo $step1vals_encoded = custom_encode($step1vals_array), ' : ', strlen($step1vals_encoded);
Maybe it's just because it's late, but I'm just tickled at this line. Not only did I make an assignment within an echo statement, I put another statement after it using echo's seldom-used (but faster-than-dot-concatenation) comma syntax (which I always forget to use). Granted, this is only debug code that I'm gonna scrap anyway, but I thought it was nice.

I want to hear about everybody else's late-night bizarro hacks. What's the worst line of code that you're the most proud of?
 
By the way, if you're wondering what custom_encode() does, it's a wee function I wrote to serialize and then encode form data so it can be passed onto a second page in a somewhat difficult-to-mess-with way. Here's the source to it and its sister function:
PHP:
function custom_encode($var) {
   return base64_encode(gzdeflate(serialize($var), ENCODE_LEVEL));
}
	
function custom_decode($string) {
   return unserialize(gzinflate(base64_decode($string), ENCODE_LEVEL));
}
ENCODE_LEVEL is a constant set by me (see the gzdeflate docs).
 
Back
Top