Allow map_deep() to work with object properties containing a reference. Restores the previous behaviour of stripslashes_deep().

Props jeff@pyebrook.com, swissspidy.
See #22300, [35252].
Fixes #35058.


git-svn-id: https://develop.svn.wordpress.org/trunk@36100 602fd350-edb4-49c9-b593-d223f7449a82
This commit is contained in:
Dion Hulse
2015-12-26 05:21:14 +00:00
parent 42aeb0af8b
commit 0ce64dd122
2 changed files with 35 additions and 5 deletions

View File

@@ -94,6 +94,30 @@ class Tests_Formatting_MapDeep extends WP_UnitTestCase {
), array( $this, 'append_baba' ) ) );
}
/**
* @ticket 35058
*/
public function test_map_deep_should_map_object_properties_passed_by_reference() {
$object_a = (object) array( 'var0' => 'a' );
$object_b = (object) array( 'var0' => &$object_a->var0, 'var1' => 'x' );
$this->assertEquals( (object) array(
'var0' => 'ababa',
'var1' => 'xbaba',
), map_deep( $object_b, array( $this, 'append_baba' ) ) );
}
/**
* @ticket 35058
*/
public function test_map_deep_should_map_array_elements_passed_by_reference() {
$array_a = array( 'var0' => 'a' );
$array_b = array( 'var0' => &$array_a['var0'], 'var1' => 'x' );
$this->assertEquals( array(
'var0' => 'ababa',
'var1' => 'xbaba',
), map_deep( $array_b, array( $this, 'append_baba' ) ) );
}
public function append_baba( $value ) {
return $value . 'baba';
}