[wp-trac] [WordPress Trac] #63627: General: Only override `$table_prefix` if not defined

WordPress Trac noreply at wordpress.org
Sat Mar 7 04:52:00 UTC 2026


#63627: General: Only override `$table_prefix` if not defined
----------------------------+--------------------------------
 Reporter:  Ninos Ego       |       Owner:  SergeyBiryukov
     Type:  enhancement     |      Status:  closed
 Priority:  normal          |   Milestone:  7.0
Component:  Bootstrap/Load  |     Version:  6.9
 Severity:  normal          |  Resolution:  fixed
 Keywords:  has-patch       |     Focuses:  php-compatibility
----------------------------+--------------------------------

Comment (by westonruter):

 This just came up in when attempting to raise the PHPStan rule level to 1
 (#64238).

 In the committed code:

 {{{#!php
 <?php
 if ( ! isset( $GLOBALS['table_prefix'] ) ) {
         $GLOBALS['table_prefix'] = $table_prefix;
 }
 }}}

 There is a PHPStan error:

 > Variable $table_prefix might not be defined.

 But I'm struggling to understand what the logic is supposed to be doing.
 At a glance it looks like dead code. In other words,
 `$GLOBALS['table_prefix']` would seem to be an alias for `$table_prefix`.
 Otherwise, how is `$table_prefix` populated?

 The [https://github.com/WordPress/wordpress-develop/pull/11189 proposed
 fix] is to add `global $table_prefix`, but I'm wary this may undo what was
 intending to be done here.

 Please see full context: https://github.com/WordPress/wordpress-
 develop/pull/11189/changes#r2898980934

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/63627#comment:6>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list