[wp-trac] [WordPress Trac] #56198: Check cache key type

WordPress Trac noreply at wordpress.org
Mon Jul 11 22:15:06 UTC 2022

#56198: Check cache key type
 Reporter:  tillkruess   |       Owner:  (none)
     Type:  enhancement  |      Status:  new
 Priority:  normal       |   Milestone:  6.1
Component:  Cache API    |     Version:  trunk
 Severity:  normal       |  Resolution:
 Keywords:  has-patch    |     Focuses:

Comment (by SergeyBiryukov):

 Replying to [comment:5 malthert]:
 > >Cache key must not be empty.
 > I think this is confusing, because 0 and '0' are valid cache keys but
 technically (in PHP terms) 'empty'.

 Good point, I would revise the suggestion then:
 * For empty strings: `Cache key must not be an empty string.`
 * For other types: `Cache key must be integer or non-empty string, %s

 > I think the single error string that is in the PR now is better.

 It may be if we find a way to improve the wording, but we should not
 insert English phrases like `'empty string'` into a translatable string,
 it results in a mix of languages that is neither English nor properly

 > Regarding translation:
 > Afaik l10n.php might not be loaded yet when this function is called at
 all. Since the object cache is loaded before l10n.php.
 > I think a function_exists() check for all translations functions in
 class-wp-object-cache.php is needed.

 Good point too! Translation functions might indeed not be included if
 WordPress is loaded in `SHORTINIT` mode. We could do a `function_exists(
 '__' )` check similar to the one found in the `_doing_it_wrong()` function
 if ( function_exists( '__' ) ) {
         $message = sprintf( __( 'Cache key must be integer or non-empty
 string, %s given.' ), $type );
 } else {
         $message = sprintf( 'Cache key must be integer or non-empty
 string, %s given.', $type );
 Another option might be to skip translation altogether.

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

More information about the wp-trac mailing list