diff --git a/src/wp-includes/class-wp-network.php b/src/wp-includes/class-wp-network.php index d835765c6b..5bb745d796 100644 --- a/src/wp-includes/class-wp-network.php +++ b/src/wp-includes/class-wp-network.php @@ -131,7 +131,7 @@ class WP_Network { */ public function __construct( $network ) { foreach ( get_object_vars( $network ) as $key => $value ) { - $this->$key = $value; + $this->__set( $key, $value ); } $this->_set_site_name(); diff --git a/tests/phpunit/tests/multisite/network.php b/tests/phpunit/tests/multisite/network.php index c7fb78e547..5ca1632469 100644 --- a/tests/phpunit/tests/multisite/network.php +++ b/tests/phpunit/tests/multisite/network.php @@ -127,6 +127,8 @@ if ( is_multisite() ) : /** * @ticket 37050 + * + * @covers WP_Network::__get */ public function test_wp_network_object_id_property_is_int() { $id = self::factory()->network->create(); @@ -136,6 +138,28 @@ if ( is_multisite() ) : $this->assertSame( (int) $id, $network->id ); } + /** + * Tests that the `WP_Network::$id` property is stored as int. + * + * Uses reflection to access the private property. + * Differs from using the public getter method, which casts to int. + * + * @ticket 62035 + * + * @covers WP_Network::__construct + */ + public function test_wp_network_object_id_property_stored_as_int() { + $id = self::factory()->network->create(); + + $network = WP_Network::get_instance( $id ); + + $reflection = new ReflectionObject( $network ); + $property = $reflection->getProperty( 'id' ); + $property->setAccessible( true ); + + $this->assertSame( (int) $id, $property->getValue( $network ) ); + } + /** * @ticket 22917 */