[wp-trac] [WordPress Trac] #33281: get_term_by() not returning false if ID does not exist

WordPress Trac noreply at wordpress.org
Tue Aug 18 17:37:40 UTC 2015


#33281: get_term_by() not returning false if ID does not exist
--------------------------+------------------------------
 Reporter:  charlestonsw  |       Owner:
     Type:  defect (bug)  |      Status:  new
 Priority:  normal        |   Milestone:  Awaiting Review
Component:  Taxonomy      |     Version:  2.3
 Severity:  normal        |  Resolution:
 Keywords:  close         |     Focuses:
--------------------------+------------------------------

Comment (by charlestonsw):

 The docs definitely need to be updated.

 As for backward compatibility - developers would be required to check for
 is_null(), false, and is_wp_error() to ensure proper functionality.   By
 forcing false the function would match the documentation and not cause the
 null corner case to be missed as any developer relying ONLY on null return
 values will have several other mainstream cases the would not be
 functioning properly.

 In my admittedly-limited research I found dozens of plugins that
 incorrectly test for only false or is_wp_error().  It appears in a number
 of prevalent plugins including several main JetPack modules.   Leaving out
 the is_null() test will cause errant behavior in a variety of taxonomy-
 related corner cases.

 I would bet that far more developers have incorrectly coded for
 false/is_wp_error() versus developers incorrectly coding for is_null()
 testing only.

 With NULL coming back from several possible logic branches it would be
 extremely difficult, and I'm guessing a very rare case, that a developer
 is relying on an is_null() test to branch their logic for one-of-several
 specific failures with this method.

 Yes, updating the docs prevents future developers from making the 2-test
 logic issue and warns them to look for is_null() as well, but I'm thinking
 more issues would be fixed by returning the "assumed false if failed" than
 would be introduced by changing null to false.

 My code has been updated to test for all 3 results and will work
 regardless of null or false.   I'm only discussing the point for the
 betterment of all WordPress installs as there are definitely a number of
 popular plugins that are missing the null return value.

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


More information about the wp-trac mailing list