[wp-trac] [WordPress Trac] #57169: Prevent saving of invalid menu_item_parent

WordPress Trac noreply at wordpress.org
Fri Jan 13 22:51:52 UTC 2023


#57169: Prevent saving of invalid menu_item_parent
-----------------------------------+-----------------------
 Reporter:  azaozz                 |       Owner:  azaozz
     Type:  defect (bug)           |      Status:  reopened
 Priority:  normal                 |   Milestone:  6.1.2
Component:  Menus                  |     Version:  6.1
 Severity:  normal                 |  Resolution:
 Keywords:  has-patch fixed-major  |     Focuses:
-----------------------------------+-----------------------

Comment (by azaozz):

 Replying to [comment:16 SergeyBiryukov]:
 >
 > {{{
 > $test = new stdClass;
 > $test->id = 123;
 >
 > var_dump( (string) $test->id ); // Should be a string.
 > var_dump( $test->id );          // Should be an integer.
 > }}}
 > Results in:
 > {{{
 > string(3) "123"
 > int(123)
 > }}}

 I see... Is that the case in all PHP versions? Was with the impression
 that casting to `(int)` was breaking the above plugin because it was
 removing the modification, but maybe it was just removing the parent as
 the modified ID is starting with a number, and casting such string to int
 would keep the number (yea, a bit weird).

 > ...except when used in array_map()

 Yep, you're right. I just did a quick grep and saw about 10 other uses.

 > So bringing back `strval()` here is inconsistent with the rest of core.

 Ah, so WordPress does forbid use of some PHP functions in some cases... As
 casting doesn't seem to change object properties, all three ways to
 temporarily convert an int to a string: `strval()`, `(string)`, and using
 double quotes appear to work in exactly the same way. It seems it is a
 question of readability and perhaps a personal preference which one is
 used. I don't really have any preferences here so feel free to change as
 you see fit.

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


More information about the wp-trac mailing list