Make WordPress Core

Opened 8 years ago

Closed 8 years ago

#37050 closed defect (bug) (fixed)

Make the `WP_Network` `id` property an int

Reported by: jeremyfelt's profile jeremyfelt Owned by: jeremyfelt's profile jeremyfelt
Milestone: 4.6 Priority: normal
Severity: normal Version: 4.4
Component: Networks and Sites Keywords: has-patch has-unit-tests
Focuses: multisite Cc:


#36717 introduced magic methods for WP_Network and we now have a mechanism for forcing the id property of WP_Network to int rather than string.

When WP_Network was introduced in [34097], the id property was incorrectly marked as int, which @jdgrimes highlighted in #35404. We adjusted this back to string for 4.5 to match the returned value.

For general developer sanity, it would be nice to cast id to an int and change the documentation. This would however break backwards compatibility for anyone doing strict comparisons with a string.

If determined to be worth it, I'd like to get it in soon so that we give things a chance to break.

Attachments (3)

37050.diff (610 bytes) - added by jeremyfelt 8 years ago.
37050.2.diff (1.3 KB) - added by flixos90 8 years ago.
37050.3.diff (1.9 KB) - added by flixos90 8 years ago.

Download all attachments as: .zip

Change History (8)

8 years ago

This ticket was mentioned in Slack in #core-multisite by jeremyfelt. View the logs.

8 years ago

8 years ago

#2 @flixos90
8 years ago

37050.2.diff makes a few adjustments:

  • instead of actually making the property an integer, leave the property as string and make it private (similar like with the other changes in #36717)
  • when writing the property, ensure it is a string
  • when reading the property, ensure it returns an integer
  • a minor additional change: I changed the default for $blog_id from integer to string so that it matches the described type

@jeremyfelt I think this method is more in line with the changes from #36717 and we keep the internals the same types like before. Let's discuss which route we wanna go. One issue with your patch was that $id was still a public property, so the magic get method that would ensure it returned an integer was never triggered.

8 years ago

#3 @flixos90
8 years ago

  • Keywords has-patch has-unit-tests added; dev-feedback 2nd-opinion removed

37050.3.diff is a combination of both previous patches. It changes the property itself to be an integer, while it also makes it private to be able to use magic methods to ensure the type.

The patch also adds a unit test for it.

After discussion at WCEU contributor day, this change is good to go in although being backwards-incompatible. The network class is not widely used and strict comparisons shouldn't be used with something as unclear as an ID field where it's unknown whether it's string or int. The change doesn't need an extra dev-note, but should be mentioned in the global multisite changes note.

#4 @jeremyfelt
8 years ago

Looks good, @flixos90. I adjusted the test name so that it's a bit more explicit - test_wp_network_object_id_property_is_int().

I'm going to handle the $blog_id adjustment in a second commit attached to #36717 so that this ID change is more clear.

#5 @jeremyfelt
8 years ago

  • Owner set to jeremyfelt
  • Resolution set to fixed
  • Status changed from new to closed

In 37870:

Multisite: Change WP_Network id property to an integer.

For consistency and developer sanity.

Props flixos90.
Fixes #37050.

Note: See TracTickets for help on using tickets.