Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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…

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

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

>Solution :

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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading