[wp-trac] [WordPress Trac] #60309: Indirect modification of overloaded property WP_Block_Type::$variations has no effect

WordPress Trac noreply at wordpress.org
Sun Jan 21 11:38:29 UTC 2024


#60309: Indirect modification of overloaded property WP_Block_Type::$variations has
no effect
--------------------------+-----------------------------
 Reporter:  thekt12       |      Owner:  thekt12
     Type:  defect (bug)  |     Status:  assigned
 Priority:  normal        |  Milestone:  Awaiting Review
Component:  General       |    Version:  trunk
 Severity:  blocker       |   Keywords:
  Focuses:                |
--------------------------+-----------------------------
 Original bug reported here - https://github.com/WordPress/wordpress-
 develop/pull/5718#issuecomment-1901940214

 This bug was introduced after the merging of
 https://core.trac.wordpress.org/ticket/59969

 The issue is

 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

-- 
Ticket URL: <https://core.trac.wordpress.org/ticket/60309>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform


More information about the wp-trac mailing list