error_log()

error_log() — Send an error message to the defined error handling routines.

Built-in function of PHP 8.5. The manual lists it as available in PHP 4, PHP 5, PHP 7, PHP 8. This page is the reference card: signature, parameters and return value, plus the changelog and the example the manual provides.

Signature

error_log(string $message, int $message_type = 0, ?string $destination = null, ?string $additional_headers = null): bool

Parameters

ParameterTypeWhat it takes
$messagestringThe error message that should be logged.
$message_typeintSays where the error should go. The possible message types are as follows:
$destination?stringThe destination. Its meaning depends on the message_type parameter as described above.
$additional_headers?stringThe extra headers. It's used when the message_type parameter is set to 1. This message type uses the same internal function as mail() does.

Return value

Returns true on success or false on failure. If message_type is zero, this function always returns true, regardless of whether the error could be logged or not.

Example

A runnable snippet:

// Send notification through the server log if we can not // connect to the database. if (!Ora_Logon($username, $password)) { error_log("Oracle database not available!", 0); } // Notify administrator by email if we run out of FOO if (!($foo = allocate_new_foo())) { error_log("Big trouble, we're all out of FOOs!", 1, "operator@example.com"); } // another way to call error_log(): error_log("You messed up!", 3, "/var/tmp/my-errors.log");

Changelog

VersionChange
8.0.0destination and additional_headers are now nullable.

All PHP 8.5 built-in functions

Reference card built from the PHP manual page error_log() (PHP documentation, CC BY 3.0). The page is generated from the manual, so the wording of the parameter and return value text follows php.net.