Skip to content

Commit 278828d

Browse files
authored
Merge pull request #369 from thecodingmachine/array_replace
FIX: Deprecated array_replace and array_replace_recursive
2 parents 0cdbee9 + 09b43b1 commit 278828d

File tree

12 files changed

+120
-112
lines changed

12 files changed

+120
-112
lines changed

deprecated/array.php

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,79 @@
44

55
use Safe\Exceptions\ArrayException;
66

7+
/**
8+
* array_replace_recursive replaces the values of
9+
* array with the same values from all the following
10+
* arrays. If a key from the first array exists in the second array, its value
11+
* will be replaced by the value from the second array. If the key exists in the
12+
* second array, and not the first, it will be created in the first array.
13+
* If a key only exists in the first array, it will be left as is.
14+
* If several arrays are passed for replacement, they will be processed
15+
* in order, the later array overwriting the previous values.
16+
*
17+
* array_replace_recursive is recursive : it will recurse into
18+
* arrays and apply the same process to the inner value.
19+
*
20+
* When the value in the first array is scalar, it will be replaced
21+
* by the value in the second array, may it be scalar or array.
22+
* When the value in the first array and the second array
23+
* are both arrays, array_replace_recursive will replace
24+
* their respective value recursively.
25+
*
26+
* @param array $array The array in which elements are replaced.
27+
* @param array $replacements Arrays from which elements will be extracted.
28+
* @return array Returns an array.
29+
* @throws ArrayException
30+
*
31+
*/
32+
function array_replace_recursive(array $array, array ...$replacements): array
33+
{
34+
error_clear_last();
35+
if ($replacements !== []) {
36+
$result = \array_replace_recursive($array, ...$replacements);
37+
} else {
38+
$result = \array_replace_recursive($array);
39+
}
40+
if ($result === null) {
41+
throw ArrayException::createFromPhpError();
42+
}
43+
return $result;
44+
}
45+
46+
/**
47+
* array_replace replaces the values of
48+
* array with values having the same keys in each of the following
49+
* arrays. If a key from the first array exists in the second array, its value
50+
* will be replaced by the value from the second array. If the key exists in the
51+
* second array, and not the first, it will be created in the first array.
52+
* If a key only exists in the first array, it will be left as is.
53+
* If several arrays are passed for replacement, they will be processed
54+
* in order, the later arrays overwriting the previous values.
55+
*
56+
* array_replace is not recursive : it will replace
57+
* values in the first array by whatever type is in the second array.
58+
*
59+
* @param array $array The array in which elements are replaced.
60+
* @param array $replacements Arrays from which elements will be extracted.
61+
* Values from later arrays overwrite the previous values.
62+
* @return array Returns an array.
63+
* @throws ArrayException
64+
*
65+
*/
66+
function array_replace(array $array, array ...$replacements): array
67+
{
68+
error_clear_last();
69+
if ($replacements !== []) {
70+
$result = \array_replace($array, ...$replacements);
71+
} else {
72+
$result = \array_replace($array);
73+
}
74+
if ($result === null) {
75+
throw ArrayException::createFromPhpError();
76+
}
77+
return $result;
78+
}
79+
780
/**
881
* array_flip returns an array in flip
982
* order, i.e. keys from array become values and values

deprecated/functionsList.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
'apc_load_constants',
1313
'apc_sma_info',
1414
'arsort',
15+
'array_replace',
16+
'array_replace_recursive',
1517
'array_combine',
1618
'array_flip',
1719
'asort',

generated/array.php

Lines changed: 0 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -4,81 +4,6 @@
44

55
use Safe\Exceptions\ArrayException;
66

7-
/**
8-
* array_replace_recursive replaces the values of
9-
* array with the same values from all the following
10-
* arrays. If a key from the first array exists in the second array, its value
11-
* will be replaced by the value from the second array. If the key exists in the
12-
* second array, and not the first, it will be created in the first array.
13-
* If a key only exists in the first array, it will be left as is.
14-
* If several arrays are passed for replacement, they will be processed
15-
* in order, the later array overwriting the previous values.
16-
*
17-
* array_replace_recursive is recursive : it will recurse into
18-
* arrays and apply the same process to the inner value.
19-
*
20-
* When the value in the first array is scalar, it will be replaced
21-
* by the value in the second array, may it be scalar or array.
22-
* When the value in the first array and the second array
23-
* are both arrays, array_replace_recursive will replace
24-
* their respective value recursively.
25-
*
26-
* @param array $array The array in which elements are replaced.
27-
* @param array $replacements Arrays from which elements will be extracted.
28-
* @return array Returns an array.
29-
* @throws ArrayException
30-
*
31-
*/
32-
function array_replace_recursive(array $array, array ...$replacements): array
33-
{
34-
error_clear_last();
35-
if ($replacements !== []) {
36-
$result = \array_replace_recursive($array, ...$replacements);
37-
} else {
38-
$result = \array_replace_recursive($array);
39-
}
40-
if ($result === null) {
41-
throw ArrayException::createFromPhpError();
42-
}
43-
return $result;
44-
}
45-
46-
47-
/**
48-
* array_replace replaces the values of
49-
* array with values having the same keys in each of the following
50-
* arrays. If a key from the first array exists in the second array, its value
51-
* will be replaced by the value from the second array. If the key exists in the
52-
* second array, and not the first, it will be created in the first array.
53-
* If a key only exists in the first array, it will be left as is.
54-
* If several arrays are passed for replacement, they will be processed
55-
* in order, the later arrays overwriting the previous values.
56-
*
57-
* array_replace is not recursive : it will replace
58-
* values in the first array by whatever type is in the second array.
59-
*
60-
* @param array $array The array in which elements are replaced.
61-
* @param array $replacements Arrays from which elements will be extracted.
62-
* Values from later arrays overwrite the previous values.
63-
* @return array Returns an array.
64-
* @throws ArrayException
65-
*
66-
*/
67-
function array_replace(array $array, array ...$replacements): array
68-
{
69-
error_clear_last();
70-
if ($replacements !== []) {
71-
$result = \array_replace($array, ...$replacements);
72-
} else {
73-
$result = \array_replace($array);
74-
}
75-
if ($result === null) {
76-
throw ArrayException::createFromPhpError();
77-
}
78-
return $result;
79-
}
80-
81-
827
/**
838
* Applies the user-defined callback function to each
849
* element of the array. This function will recurse

generated/curl.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2588,7 +2588,7 @@ function curl_multi_setopt(\CurlMultiHandle $multi_handle, int $option, $value):
25882588
*
25892589
* CURLOPT_PROXY_TLSAUTH_USERNAME
25902590
*
2591-
* Tusername to use for the HTTPS proxy TLS authentication method specified with the
2591+
* The username to use for the HTTPS proxy TLS authentication method specified with the
25922592
* CURLOPT_PROXY_TLSAUTH_TYPE option. Requires that the
25932593
* CURLOPT_PROXY_TLSAUTH_PASSWORD option to also be set.
25942594
*

generated/exec.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,10 +85,10 @@ function passthru(string $command, ?int &$result_code = null): void
8585
* @param int $priority The new priority value, the value of this may differ on platforms.
8686
*
8787
* On Unix, a low value, such as -20 means high priority
88-
* wheras a positive value have a lower priority.
88+
* whereas positive values have a lower priority.
8989
*
90-
* For Windows the priority parameter have the
91-
* following meanings:
90+
* For Windows the priority parameter has the
91+
* following meaning:
9292
* @throws ExecException
9393
*
9494
*/

generated/filesystem.php

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1240,6 +1240,13 @@ function lstat(string $filename): array
12401240
* Attempts to create the directory specified by directory.
12411241
*
12421242
* @param string $directory The directory path.
1243+
* A URL can be used as a
1244+
* filename with this function if the fopen wrappers have been enabled.
1245+
* See fopen for more details on how to specify the
1246+
* filename. See the for links to information
1247+
* about what abilities the various wrappers have, notes on their usage,
1248+
* and information on any predefined variables they may
1249+
* provide.
12431250
* @param int $permissions The permissions are 0777 by default, which means the widest possible
12441251
* access. For more information on permissions, read the details
12451252
* on the chmod page.
@@ -1250,8 +1257,8 @@ function lstat(string $filename): array
12501257
* which means it should have a leading zero. The permissions is also modified
12511258
* by the current umask, which you can change using
12521259
* umask.
1253-
* @param bool $recursive Allows the creation of nested directories specified in the
1254-
* directory.
1260+
* @param bool $recursive If TRUE, then any parent directories to the directory specified will
1261+
* also be created, with the same permissions.
12551262
* @param resource $context A context stream
12561263
* resource.
12571264
* @throws FilesystemException

generated/functionsList.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,6 @@
1414
'apcu_inc',
1515
'apcu_sma_info',
1616
'apc_fetch',
17-
'array_replace',
18-
'array_replace_recursive',
1917
'array_walk_recursive',
2018
'assert_options',
2119
'base64_decode',

generated/json.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
/**
88
* Returns a string containing the JSON representation of the supplied
9-
* value.
9+
* value. If the parameter is an array or object,
10+
* it will be serialized recursively.
11+
*
12+
* If a value to be serialized is an object, then by default only publicly visible
13+
* properties will be included. Alternatively, a class may implement JsonSerializable
14+
* to control how its values are serialized to JSON.
1015
*
1116
* The encoding is affected by the supplied flags
1217
* and additionally the encoding of float values depends on the value of

generated/ldap.php

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -239,36 +239,36 @@ function ldap_exop_whoami($ldap)
239239

240240

241241
/**
242-
* Performs an extended operation on the specified link with
243-
* reqoid the OID of the operation and
244-
* reqdata the data.
242+
* Performs an extended operation on the specified ldap with
243+
* request_oid the OID of the operation and
244+
* request_data the data.
245245
*
246246
* @param resource $ldap An LDAP\Connection instance, returned by ldap_connect.
247-
* @param string $reqoid The extended operation request OID. You may use one of LDAP_EXOP_START_TLS, LDAP_EXOP_MODIFY_PASSWD, LDAP_EXOP_REFRESH, LDAP_EXOP_WHO_AM_I, LDAP_EXOP_TURN, or a string with the OID of the operation you want to send.
248-
* @param string $reqdata The extended operation request data. May be NULL for some operations like LDAP_EXOP_WHO_AM_I, may also need to be BER encoded.
249-
* @param array|null $serverctrls Array of LDAP Controls to send with the request.
250-
* @param string|null $retdata Will be filled with the extended operation response data if provided.
247+
* @param string $request_oid The extended operation request OID. You may use one of LDAP_EXOP_START_TLS, LDAP_EXOP_MODIFY_PASSWD, LDAP_EXOP_REFRESH, LDAP_EXOP_WHO_AM_I, LDAP_EXOP_TURN, or a string with the OID of the operation you want to send.
248+
* @param string $request_data The extended operation request data. May be NULL for some operations like LDAP_EXOP_WHO_AM_I, may also need to be BER encoded.
249+
* @param array|null $controls Array of LDAP Controls to send with the request.
250+
* @param string|null $response_data Will be filled with the extended operation response data if provided.
251251
* If not provided you may use ldap_parse_exop on the result object
252252
* later to get this data.
253-
* @param string|null $retoid Will be filled with the response OID if provided, usually equal to the request OID.
254-
* @return resource|bool When used with retdata, returns TRUE on success.
255-
* When used without retdata, returns a result identifier.
253+
* @param string|null $response_oid Will be filled with the response OID if provided, usually equal to the request OID.
254+
* @return resource|bool When used with response_data, returns TRUE on success.
255+
* When used without response_data, returns a result identifier.
256256
* @throws LdapException
257257
*
258258
*/
259-
function ldap_exop($ldap, string $reqoid, string $reqdata = null, ?array $serverctrls = null, ?string &$retdata = null, ?string &$retoid = null)
259+
function ldap_exop($ldap, string $request_oid, string $request_data = null, ?array $controls = null, ?string &$response_data = null, ?string &$response_oid = null)
260260
{
261261
error_clear_last();
262-
if ($retoid !== null) {
263-
$result = \ldap_exop($ldap, $reqoid, $reqdata, $serverctrls, $retdata, $retoid);
264-
} elseif ($retdata !== null) {
265-
$result = \ldap_exop($ldap, $reqoid, $reqdata, $serverctrls, $retdata);
266-
} elseif ($serverctrls !== null) {
267-
$result = \ldap_exop($ldap, $reqoid, $reqdata, $serverctrls);
268-
} elseif ($reqdata !== null) {
269-
$result = \ldap_exop($ldap, $reqoid, $reqdata);
262+
if ($response_oid !== null) {
263+
$result = \ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data, $response_oid);
264+
} elseif ($response_data !== null) {
265+
$result = \ldap_exop($ldap, $request_oid, $request_data, $controls, $response_data);
266+
} elseif ($controls !== null) {
267+
$result = \ldap_exop($ldap, $request_oid, $request_data, $controls);
268+
} elseif ($request_data !== null) {
269+
$result = \ldap_exop($ldap, $request_oid, $request_data);
270270
} else {
271-
$result = \ldap_exop($ldap, $reqoid);
271+
$result = \ldap_exop($ldap, $request_oid);
272272
}
273273
if ($result === false) {
274274
throw LdapException::createFromPhpError();

generated/pcntl.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@
1111
* man page for specific details.
1212
*
1313
* @param int $process_id If NULL, the process id of the current process is used.
14-
* @param int $mode One of PRIO_PGRP, PRIO_USER
15-
* or PRIO_PROCESS.
14+
* @param int $mode One of PRIO_PGRP, PRIO_USER,
15+
* PRIO_PROCESS,
16+
* PRIO_DARWIN_BG or PRIO_DARWIN_THREAD.
1617
* @return int pcntl_getpriority returns the priority of the process. A lower numerical value causes more favorable
1718
* scheduling.
1819
* @throws PcntlException
@@ -46,8 +47,9 @@ function pcntl_getpriority(int $process_id = null, int $mode = PRIO_PROCESS): in
4647
* system types and kernel versions, please see your system's setpriority(2)
4748
* man page for specific details.
4849
* @param int $process_id If NULL, the process id of the current process is used.
49-
* @param int $mode One of PRIO_PGRP, PRIO_USER
50-
* or PRIO_PROCESS.
50+
* @param int $mode One of PRIO_PGRP, PRIO_USER,
51+
* PRIO_PROCESS,
52+
* PRIO_DARWIN_BG or PRIO_DARWIN_THREAD.
5153
* @throws PcntlException
5254
*
5355
*/

0 commit comments

Comments
 (0)