[ Content | View menu ]

PHP Insanity VIII

Mark Mzyk | May 1, 2008

If you’d rather not read what I have to say about today’s PHP Insanity, you can attempt to find it for yourself on the php.net error_log man page.

In my daily work, I use the error_log function often.  It was shown to me by a coworker and I’ve found it handy ever since.  However, my coworker, in showing me how to use it, showed me his default way of using it, which included always passing one of the argument as the int 3.  With the argument being the int 3, it was clear that there must be more options available.

Several months have passed, and it wasn’t until the other day that I became curious enough to look up what other options there were.  Here is the list of the int arguments that can be passed to error_log, just in case you didn’t go to the man page to look them up for yourself:

  • 0: message is sent to PHP’s system logger, using the Operating System’s system logging mechanism or a file, depending on what the error_log configuration directive is set to. This is the default option.
  • 1: message is sent by email to the address in the destination parameter. This is the only message type where the fourth parameter, extra_headers is used.
  • 2: No longer an option.
  • 3: message is appended to the file destination . A newline is not automatically added to the end of the message string.

Did you notice which one of those wasn’t like the others?

I don’t know what caused 2 to be removed, but I love the gaping hole that was left in its place.  Why couldn’t 2 have been changed so that it was an alias for 3, instead of just leaving it open?  Now, should someone pick 2, wondering what it does, anything could happen.  Hopefully PHP fatals, but I haven’t tried it, so I’m not sure how PHP behaves.

PHP has taught me not to trust it, and the more examples like this that I find, the more I realize that I’m right not to trust it.  The next project at work might have me using Python.  I’m looking forward to the change of scenery.