Using constants in PHP, how to read a value defined using CONSTANT

I am accessing a Wordpress file (wp-config.php) and using the database connection parameters. This is working ok but it seems I can access using either CONSTANT(“DB_NAME”) or simply DB_NAME.

My question is what is the difference and which is best

From the manual:

constant() is useful if you need to retrieve the value of a constant, but do not know its name. I.e. it is stored in a variable or returned by a function.

If you do know the constant’s name, there’s nothing to be gained by using the function.

2 Likes

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.