[wp-trac] [WordPress Trac] #59969: Conditional loading `build_template_part_block_variations` for performance improvement

WordPress Trac noreply at wordpress.org
Mon Feb 5 18:47:06 UTC 2024


#59969: Conditional loading `build_template_part_block_variations` for performance
improvement
--------------------------------------------+--------------------------
 Reporter:  thekt12                         |       Owner:  joemcgill
     Type:  defect (bug)                    |      Status:  reopened
 Priority:  normal                          |   Milestone:  6.5
Component:  General                         |     Version:
 Severity:  normal                          |  Resolution:
 Keywords:  has-patch needs-dev-note close  |     Focuses:  performance
--------------------------------------------+--------------------------

Comment (by westonruter):

 Replying to [comment:63 joemcgill]:
 > The PHPUnit tests in the Gutenberg plugin for the Nav Link block has
 been fixed, but this did expose an issue where indirectly modifying the
 overloaded variations property no longer works. Copying the description
 from @thekt12 on #60309 here so we can keep discussion of this issue all
 in one place:
 >
 > > The setting of WP_Block_Type::$variations from the outside in a normal
 way like $block_type-> variations = array( array(...), ... ) works fine.
 However if we try to set it especially $block_type->variations[] = array(
 ... ); it throws Indirect modification of overloaded property
 WP_Block_Type::$variations has no effect.
 > >
 > > The reason is WP_Block_Type::$variations is only accessible via the
 magic __get, __set function. __get always returns a copy of the original
 attribute variable and not the reference of the actual attribute variable.
 > >
 > > So, when we do $block_type->variations = array( array(...), ... ) we
 are only setting the temporary variable which is then processed by __set
 to set the original attribute.
 > >
 > > But this fails when we try to set the variable in a way where it's
 original state is checked like in ->$block_type->variations[] = array( ...
 );; Here, we try to add to the original variable array.
 > >
 > > The way to fix this is by trying to get the reference of the original
 variable from __get instead of copy of variable

 I don't think this is necessarily the case. A magic getter can return by
 reference as I see from https://stackoverflow.com/a/13186679/93579

 Test case: https://3v4l.org/TT2UD

 Here's a patch to fix the back-compat issue: https://github.com/WordPress
 /wordpress-develop/pull/6030

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


More information about the wp-trac mailing list