Galathil
Galathil

Reputation: 3

Constant already defined in function prototype

I have this code :

<?php

define('LOG_DEBUG','DEBUG');
define('LOG_ERROR','ERROR');

function trace($message,$level=LOG_DEBUG){
    echo '['.date('Y-m-d H:i:s').' '.$level.'] '.$message."\n";
}

trace('test debug message');
trace('test error message', LOG_ERROR);

Output (Running in PHP 7.4) :

PHP Notice:  Constant LOG_DEBUG already defined in /var/www/mail_dumper/PHPMailDumper.php on line 3
[2022-02-11 22:00:33 7] test debug message
[2022-02-11 22:00:33 ERROR] test error message

I don't understand the notice...

I tried to affect LOG_DEBUG to default value and not try to reaffect?

And... In trace test we see a "7" in output?

Upvotes: 0

Views: 1041

Answers (1)

nickb
nickb

Reputation: 59699

You're getting this warning because LOG_DEBUG is a predefined PHP constant for the syslog function.

Upvotes: 1

Related Questions