Skip to content

Commit 54ae0ee

Browse files
committed
test for array_walk_recursive, see #621
1 parent 1b99e64 commit 54ae0ee

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/DeprecationTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,30 @@ function_exists('Safe\array_flip'),
2727
);
2828
}
2929

30+
public function testFunctionWhichBecameSafeWithReferences(): void
31+
{
32+
// array_walk_recursive is unsafe in 8.3 and safe in 8.4, and one of
33+
// the parameters is a reference, which wasn't handled by the original
34+
// no-op wrapper
35+
// See https://github.com/thecodingmachine/safe/issues/621
36+
$this->assertTrue(
37+
function_exists('Safe\array_walk_recursive'),
38+
"Safe\array_walk_recursive should exist, even in php 8.4 (where it ".
39+
"is safe natively), because it was unsafe in 8.1"
40+
);
41+
$data = [
42+
['foo', 'far'],
43+
['bar', 'baz'],
44+
];
45+
array_walk_recursive($data, static function (&$item) {
46+
$item = 111;
47+
});
48+
$this->assertEquals(
49+
$data,
50+
[[111, 111], [111, 111]]
51+
);
52+
}
53+
3054
public function testIntroducedFunction(): void
3155
{
3256
// This function was introduced in php 8.2, so we should only

0 commit comments

Comments
 (0)