[wp-trac] [WordPress Trac] #46923: $wpdb->get_var() — empty sting becomes a NULL

WordPress Trac noreply at wordpress.org
Mon Apr 15 17:07:42 UTC 2019


#46923: $wpdb->get_var() — empty sting becomes a NULL
--------------------------+------------------------------
 Reporter:  Tkama         |       Owner:  (none)
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Database      |     Version:  5.1.1
 Severity:  normal        |  Resolution:
 Keywords:                |     Focuses:
--------------------------+------------------------------
Changes (by SergeyBiryukov):

 * component:  General => Database


Old description:

> Because of the following condition, we get `NULL`, even if a real field
> value is an empty string!
>
> {{{#!php
> <?php
> return ( isset( $values[ $x ] ) && $values[ $x ] !== '' ) ? $values[ $x ]
> : null;
> }}}
>
> [See `wp-db.php` Line 2477](https://wp-kama.ru/filecode/wp-includes/wp-
> db.php#L2460-2478)
>
> I think it is better to delete `$values[ $x ] !== ''` check and return
> field value as it is if it exists - what is usually meant by NULL in PHP
> (empty string is not null!).

New description:

 Because of the following condition, we get `NULL`, even if a real field
 value is an empty string!

 {{{#!php
 <?php
 return ( isset( $values[ $x ] ) && $values[ $x ] !== '' ) ? $values[ $x ]
 : null;
 }}}

 [source:tags/5.1.1/src/wp-includes/wp-db.php?marks=2460-2478#L2455 See
 `wp-db.php` Line 2477]

 I think it is better to delete `$values[ $x ] !== ''` check and return
 field value as it is if it exists - what is usually meant by NULL in PHP
 (empty string is not null!).

--

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


More information about the wp-trac mailing list