[wp-trac] [WordPress Trac] #35560: Use of undefined constant DB_USER - assumed 'DB_USER'
WordPress Trac
noreply at wordpress.org
Fri Jan 22 01:55:06 UTC 2016
#35560: Use of undefined constant DB_USER - assumed 'DB_USER'
-------------------------------+------------------------------
Reporter: mariusvw | Owner:
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Database | Version:
Severity: normal | Resolution:
Keywords: reporter-feedback | Focuses:
-------------------------------+------------------------------
Old description:
> At my work we work in strict mode where every error needs to be solved.
> Even undefined errors will fail the test platform.
>
> In wp-includes/load.php at line 369 it is assumed that DB_USER,
> DB_PASSWORD, DB_NAME and DB_HOST are defined as constants.
>
> When you don't have a config yet this is not the case.
> The solution would be muting the error or defining the constants as null.
>
> # Solution 1, prepend above the "new wpdb()":
> if (!defined('DB_USER')) {
> define('DB_USER', null);
> }
> if (!defined('DB_PASSWORD')) {
> define('DB_PASSWORD', null);
> }
> if (!defined('DB_NAME')) {
> define('DB_NAME', null);
> }
> if (!defined('DB_HOST')) {
> define('DB_HOST', null);
> }
>
> # Solution 2, modify the "new wpdb()" line:
> $wpdb = new wpdb( @DB_USER, @DB_PASSWORD, @DB_NAME, @DB_HOST );
>
> Where I would prefer to use solution 1.
New description:
At my work we work in strict mode where every error needs to be solved.
Even undefined errors will fail the test platform.
In wp-includes/load.php at line 369 it is assumed that DB_USER,
DB_PASSWORD, DB_NAME and DB_HOST are defined as constants.
When you don't have a config yet this is not the case.
The solution would be muting the error or defining the constants as null.
# Solution 1, prepend above the "new wpdb()":
{{{
if (!defined('DB_USER')) {
define('DB_USER', null);
}
if (!defined('DB_PASSWORD')) {
define('DB_PASSWORD', null);
}
if (!defined('DB_NAME')) {
define('DB_NAME', null);
}
if (!defined('DB_HOST')) {
define('DB_HOST', null);
}
}}}
# Solution 2, modify the "new wpdb()" line:
{{{$wpdb = new wpdb( @DB_USER, @DB_PASSWORD, @DB_NAME, @DB_HOST );}}}
Where I would prefer to use solution 1.
--
Comment (by dd32):
> It also occurs when you do have a wp-config.php but still have to run
the setup of wordpress.
That shouldn't happen, as if you have a `wp-config.php` file, then those
constants should already be defined.
The only scenario where these notices can be generated is when WordPress
is yet to have a valid `wp-config.php` generated for it, or the file lacks
those constants because it's using a `wp-content/db.php` dropin which
doesn't use those constants.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/35560#comment:3>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list