Skip to content

Commit 01b4726

Browse files
Add _path suffix to function names
1 parent b947093 commit 01b4726

6 files changed

Lines changed: 46 additions & 46 deletions

File tree

ext/standard/array.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6967,7 +6967,7 @@ static zval* array_get_nested(HashTable *ht, HashTable *path)
69676967
/* }}} */
69686968

69696969
/* {{{ Retrieves a value from a deeply nested array using an array path */
6970-
PHP_FUNCTION(array_get)
6970+
PHP_FUNCTION(array_get_path)
69716971
{
69726972
zval *array;
69736973
zval *path;
@@ -6998,7 +6998,7 @@ PHP_FUNCTION(array_get)
69986998
/* }}} */
69996999

70007000
/* {{{ Checks whether a given item exists in an array using an array path */
7001-
PHP_FUNCTION(array_has)
7001+
PHP_FUNCTION(array_has_path)
70027002
{
70037003
zval *array;
70047004
zval *path;

ext/standard/basic_functions.stub.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1906,12 +1906,12 @@ function key_exists($key, array $array): bool {}
19061906
/**
19071907
* @compile-time-eval
19081908
*/
1909-
function array_get(array $array, array $path, mixed $default = null): mixed {}
1909+
function array_get_path(array $array, array $path, mixed $default = null): mixed {}
19101910

19111911
/**
19121912
* @compile-time-eval
19131913
*/
1914-
function array_has(array $array, array $path): bool {}
1914+
function array_has_path(array $array, array $path): bool {}
19151915

19161916
/**
19171917
* @compile-time-eval

ext/standard/basic_functions_arginfo.h

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/basic_functions_decl.h

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ext/standard/tests/array/array_get.phpt renamed to ext/standard/tests/array/array_get_path.phpt

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,72 +1,72 @@
11
--TEST--
2-
Test array_get() function
2+
Test array_get_path() function
33
--FILE--
44
<?php
5-
echo "*** Testing array_get() ***\n";
5+
echo "*** Testing array_get_path() ***\n";
66

77
// Basic nested array access
88
$array = ['products' => ['desk' => ['price' => 100]]];
99

1010
// Test nested access with array path
11-
var_dump(array_get($array, ['products', 'desk', 'price']));
11+
var_dump(array_get_path($array, ['products', 'desk', 'price']));
1212

1313
// Test with default value when path doesn't exist
14-
var_dump(array_get($array, ['products', 'desk', 'discount'], 5));
14+
var_dump(array_get_path($array, ['products', 'desk', 'discount'], 5));
1515

1616
// Test simple path with single level
1717
$simple = ['name' => 'John', 'age' => 30];
18-
var_dump(array_get($simple, ['name']));
19-
var_dump(array_get($simple, ['missing'], 'default'));
18+
var_dump(array_get_path($simple, ['name']));
19+
var_dump(array_get_path($simple, ['missing'], 'default'));
2020

2121
// Test single level key that doesn't exist
22-
var_dump(array_get($array, ['missing']));
22+
var_dump(array_get_path($array, ['missing']));
2323

2424
// Test with integer key in path
2525
$users = ['users' => [['name' => 'Alice'], ['name' => 'Bob']]];
26-
var_dump(array_get($users, ['users', 0, 'name']));
27-
var_dump(array_get($users, ['users', 1, 'name']));
26+
var_dump(array_get_path($users, ['users', 0, 'name']));
27+
var_dump(array_get_path($users, ['users', 1, 'name']));
2828

2929
// Test nested with missing intermediate key
30-
var_dump(array_get($array, ['products', 'chair', 'price'], 75));
30+
var_dump(array_get_path($array, ['products', 'chair', 'price'], 75));
3131

3232
// Test with invalid segment type in array path
3333
try {
34-
var_dump(array_get($array, ['products', new stdClass(), 'price'], 'invalid'));
34+
var_dump(array_get_path($array, ['products', new stdClass(), 'price'], 'invalid'));
3535
} catch (TypeError $e) {
3636
echo $e->getMessage() . "\n";
3737
}
3838

3939
// Test with references - ensure returned value is a copy, not a reference
4040
$ref_array = ['data' => ['value' => 'original']];
4141
$ref =& $ref_array['data']['value'];
42-
$result = array_get($ref_array, ['data', 'value']);
42+
$result = array_get_path($ref_array, ['data', 'value']);
4343
var_dump($result);
4444
$ref = 'modified';
4545
var_dump($result); // Should still be 'original' (not affected by reference change)
4646

4747
// Test with default value being a reference
4848
$default_value = 'default';
4949
$default_ref =& $default_value;
50-
$result_with_ref_default = array_get($ref_array, ['missing', 'key'], $default_ref);
50+
$result_with_ref_default = array_get_path($ref_array, ['missing', 'key'], $default_ref);
5151
var_dump($result_with_ref_default);
5252
$default_value = 'changed';
5353
var_dump($result_with_ref_default); // Should still be 'default' (not affected by reference change)
5454

5555
// Test with reference to an array in the path
5656
$array2 = ['world'];
5757
$array_with_ref = ['hello' => &$array2];
58-
var_dump(array_get($array_with_ref, ['hello', 0]));
58+
var_dump(array_get_path($array_with_ref, ['hello', 0]));
5959

6060
// Test with path segment that is a reference
6161
$key1 = 'products';
6262
$key2 = 'desk';
6363
$path_with_refs = [&$key1, &$key2, 'price'];
64-
var_dump(array_get($array, $path_with_refs));
64+
var_dump(array_get_path($array, $path_with_refs));
6565

6666
echo "Done";
6767
?>
6868
--EXPECT--
69-
*** Testing array_get() ***
69+
*** Testing array_get_path() ***
7070
int(100)
7171
int(5)
7272
string(4) "John"

ext/standard/tests/array/array_has.phpt renamed to ext/standard/tests/array/array_has_path.phpt

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,58 +1,58 @@
11
--TEST--
2-
Test array_has() function
2+
Test array_has_path() function
33
--FILE--
44
<?php
5-
echo "*** Testing array_has() ***\n";
5+
echo "*** Testing array_has_path() ***\n";
66

77
// Basic array
88
$array = ['product' => ['name' => 'Desk', 'price' => 100]];
99

1010
// Test nested key exists with array path
11-
var_dump(array_has($array, ['product', 'name']));
11+
var_dump(array_has_path($array, ['product', 'name']));
1212

1313
// Test nested key doesn't exist
14-
var_dump(array_has($array, ['product', 'color']));
14+
var_dump(array_has_path($array, ['product', 'color']));
1515

1616
// Test intermediate key doesn't exist
17-
var_dump(array_has($array, ['category', 'name']));
17+
var_dump(array_has_path($array, ['category', 'name']));
1818

1919
// Test simple path with single level
2020
$simple = ['name' => 'John', 'age' => 30];
21-
var_dump(array_has($simple, ['name']));
22-
var_dump(array_has($simple, ['missing']));
21+
var_dump(array_has_path($simple, ['name']));
22+
var_dump(array_has_path($simple, ['missing']));
2323

2424
// Test with integer key in path
2525
$users = ['users' => [['name' => 'Alice'], ['name' => 'Bob']]];
26-
var_dump(array_has($users, ['users', 0, 'name']));
27-
var_dump(array_has($users, ['users', 1, 'name']));
28-
var_dump(array_has($users, ['users', 2, 'name']));
26+
var_dump(array_has_path($users, ['users', 0, 'name']));
27+
var_dump(array_has_path($users, ['users', 1, 'name']));
28+
var_dump(array_has_path($users, ['users', 2, 'name']));
2929

3030
// Test with value that is null (key exists, but value is null)
3131
$withNull = ['key' => null];
32-
var_dump(array_has($withNull, ['key']));
32+
var_dump(array_has_path($withNull, ['key']));
3333

3434
// Test with invalid segment type in array path
3535
try {
36-
var_dump(array_has($array, ['product', new stdClass()]));
36+
var_dump(array_has_path($array, ['product', new stdClass()]));
3737
} catch (TypeError $e) {
3838
echo $e->getMessage() . "\n";
3939
}
4040

4141
// Test with reference to an array in the path
4242
$array2 = ['world'];
4343
$array_with_ref = ['hello' => &$array2];
44-
var_dump(array_has($array_with_ref, ['hello', 0]));
44+
var_dump(array_has_path($array_with_ref, ['hello', 0]));
4545

4646
// Test with path segment that is a reference
4747
$key1 = 'product';
4848
$key2 = 'name';
4949
$path_with_refs = [&$key1, &$key2];
50-
var_dump(array_has($array, $path_with_refs));
50+
var_dump(array_has_path($array, $path_with_refs));
5151

5252
echo "Done";
5353
?>
5454
--EXPECT--
55-
*** Testing array_has() ***
55+
*** Testing array_has_path() ***
5656
bool(true)
5757
bool(false)
5858
bool(false)

0 commit comments

Comments
 (0)