View Single Post
Old 04-25-2009, 11:22 AM   #2 (permalink)
Salathe
Moderateur
RegEx Guru PHP Guru Top Contributor Advanced Programmer 
 
Salathe's Avatar
 
Join Date: Apr 2007
Posts: 1,393
Thanks: 5
Salathe is on a distinguished road
Default

Oh where to start.
  1. There is absolutely no need for the return since you call exit.
  2. Whilst they might "just work", the built-in magic constants should be uppercased: __FUNCTION__, __FILE__ and __LINE__.
  3. What is this all about: | -9999 . false . null . ThisIsNotAVariable .. As far as I can see it serves no practical purpose (and is the cause of your "bug").
  4. Personally, I think things would look much prettier with sprintf.

Now onto the "bug", which really isn't one. The root of the problem is that you use the "bitwise or" (|) operator which is playing around with the bits in your strings. It is basically taking the string before the | and "or"ing that with the string after it. The output will vary but given the following:
Code:
$_SERVER['SERVER_SOFTWARE'] = 'my server software';
basename(__FILE__)          = 'bug.php';
$Str_CalledFunction         = 'bug';
__LINE__                    = 3;
mysql_error()               = '';
ThisIsNotAVariable          = 'ThisIsNotAVariable';
Then the line will try to output the following expression:
Code:
'[my server software] [bug.php] [bug] [3] [' | '-9999ThisIsNotAVariable].'
The result, for this case, being:
Code:
}y9{uzw{sovuwarm}bg}o.php] [bug] [3] [
and for my local server (Apache/2.2.9 (Unix) PHP/5.3.0RC2-dev):
Code:
yyy{|mososntiWo{yibmo}ssl/2.2.9 OpenSSL/0.9.7l DAV/2 PHP/5.3.0RC2-dev mod_perl/2.0.2 Perl/v5.8.8] [bug.php] [fail] [9] [
Salathe is offline  
Reply With Quote