diff options
author | Nikita Popov <nikita.ppv@gmail.com> | 2020-11-30 16:45:48 +0100 |
---|---|---|
committer | Nikita Popov <nikita.ppv@gmail.com> | 2021-02-11 21:46:13 +0100 |
commit | b10416a652d26577a22fe0b183b2258b20c8bb86 (patch) | |
tree | 3b79102286b2307575f487bf97d572ffc292631d /ext/spl | |
parent | f06895488a5fabd27ac4c2e66a9d311f14d8594e (diff) | |
download | php-git-b10416a652d26577a22fe0b183b2258b20c8bb86.tar.gz |
Deprecate passing null to non-nullable arg of internal function
This deprecates passing null to non-nullable scale arguments of
internal functions, with the eventual goal of making the behavior
consistent with userland functions, where null is never accepted
for non-nullable arguments.
This change is expected to cause quite a lot of fallout. In most
cases, calling code should be adjusted to avoid passing null. In
some cases, PHP should be adjusted to make some function arguments
nullable. I have already fixed a number of functions before landing
this, but feel free to file a bug if you encounter a function that
doesn't accept null, but probably should. (The rule of thumb for
this to be applicable is that the function must have special behavior
for 0 or "", which is distinct from the natural behavior of the
parameter.)
RFC: https://wiki.php.net/rfc/deprecate_null_to_scalar_internal_arg
Closes GH-6475.
Diffstat (limited to 'ext/spl')
-rw-r--r-- | ext/spl/tests/SplFixedArray__construct_param_null.phpt | 3 | ||||
-rw-r--r-- | ext/spl/tests/SplFixedArray_setSize_param_null.phpt | 3 | ||||
-rw-r--r-- | ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter3.phpt | 4 | ||||
-rw-r--r-- | ext/spl/tests/bug46051.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/bug61527.phpt | 4 | ||||
-rw-r--r-- | ext/spl/tests/bug65387.phpt | 4 | ||||
-rw-r--r-- | ext/spl/tests/bug75717.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/fixedarray_011.phpt | 14 | ||||
-rw-r--r-- | ext/spl/tests/fixedarray_014.phpt | 2 | ||||
-rw-r--r-- | ext/spl/tests/iterator_044.phpt | 8 | ||||
-rw-r--r-- | ext/spl/tests/regexIterator_flags_basic.phpt | 2 |
11 files changed, 22 insertions, 26 deletions
diff --git a/ext/spl/tests/SplFixedArray__construct_param_null.phpt b/ext/spl/tests/SplFixedArray__construct_param_null.phpt index 919c72021a..acd9d44af5 100644 --- a/ext/spl/tests/SplFixedArray__construct_param_null.phpt +++ b/ext/spl/tests/SplFixedArray__construct_param_null.phpt @@ -10,7 +10,8 @@ $array = new SplFixedArray( NULL ); print_r( $array ); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: SplFixedArray::__construct(): Passing null to parameter #1 ($size) of type int is deprecated in %s on line %d SplFixedArray Object ( ) diff --git a/ext/spl/tests/SplFixedArray_setSize_param_null.phpt b/ext/spl/tests/SplFixedArray_setSize_param_null.phpt index ddb37be9f0..dd98935f2f 100644 --- a/ext/spl/tests/SplFixedArray_setSize_param_null.phpt +++ b/ext/spl/tests/SplFixedArray_setSize_param_null.phpt @@ -8,6 +8,7 @@ $fixed_array = new SplFixedArray(2); $fixed_array->setSize(null); var_dump($fixed_array); ?> ---EXPECT-- +--EXPECTF-- +Deprecated: SplFixedArray::setSize(): Passing null to parameter #1 ($size) of type int is deprecated in %s on line %d object(SplFixedArray)#1 (0) { } diff --git a/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter3.phpt b/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter3.phpt index bc9f78a1ca..6934c3af1b 100644 --- a/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter3.phpt +++ b/ext/spl/tests/SplObjectStorage_unserialize_invalid_parameter3.phpt @@ -1,5 +1,5 @@ --TEST-- -Check that SplObjectStorage::unserialize doesn't throws exception when NULL passed +Check that SplObjectStorage::unserialize doesn't throws exception when empty string passed --CREDITS-- PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) --FILE-- @@ -8,7 +8,7 @@ PHPNW Testfest 2009 - Simon Westcott (swestcott@gmail.com) $s = new SplObjectStorage(); try { - $s->unserialize(NULL); + $s->unserialize(''); } catch(UnexpectedValueException $e) { echo $e->getMessage(); } diff --git a/ext/spl/tests/bug46051.phpt b/ext/spl/tests/bug46051.phpt index cebe8a52d7..535dd2ddae 100644 --- a/ext/spl/tests/bug46051.phpt +++ b/ext/spl/tests/bug46051.phpt @@ -6,7 +6,7 @@ Bug #46051 (SplFileInfo::openFile - memory overlap) $x = new splfileinfo(__FILE__); try { - $x->openFile(NULL, NULL, []); + $x->openFile("", false, []); } catch (TypeError $e) { } var_dump($x->getPathName()); diff --git a/ext/spl/tests/bug61527.phpt b/ext/spl/tests/bug61527.phpt index fa8291228c..f068897246 100644 --- a/ext/spl/tests/bug61527.phpt +++ b/ext/spl/tests/bug61527.phpt @@ -42,12 +42,12 @@ var_dump($ai2->next()); var_dump($ai2->key()); /* testing RecursiveArrayIterator */ -$ao3 = new ArrayObject(array(), NULL, 'RecursiveArrayIterator'); +$ao3 = new ArrayObject(array(), 0, 'RecursiveArrayIterator'); $ai3 = $ao3->getIterator(); var_dump($ai3->getChildren()); -$ao4 = new ArrayObject(array(1, 2), NULL, 'RecursiveArrayIterator'); +$ao4 = new ArrayObject(array(1, 2), 0, 'RecursiveArrayIterator'); $ai4 = $ao4->getIterator(); $ai4->next(); diff --git a/ext/spl/tests/bug65387.phpt b/ext/spl/tests/bug65387.phpt index a5b028954c..e5d501ccf1 100644 --- a/ext/spl/tests/bug65387.phpt +++ b/ext/spl/tests/bug65387.phpt @@ -31,13 +31,13 @@ $it2 = new RecursiveCallbackFilterIterator($it, function($elem) use(&$it2) { // Cache $it = new ArrayIterator(); $it2 = new CachingIterator($it, CachingIterator::FULL_CACHE); -$it2[] = $it2; +$it2['x'] = $it2; $it2->next(); // Recursive cache $it = new RecursiveArrayIterator(); $it2 = new RecursiveCachingIterator($it, CachingIterator::FULL_CACHE); -$it2[] = $it2; +$it2['x'] = $it2; $it2->next(); // Append diff --git a/ext/spl/tests/bug75717.phpt b/ext/spl/tests/bug75717.phpt index 77226e1099..920dda9c53 100644 --- a/ext/spl/tests/bug75717.phpt +++ b/ext/spl/tests/bug75717.phpt @@ -8,7 +8,7 @@ function flatten(array $nestedArraysAndStrings){ $iter = new RecursiveIteratorIterator( new RecursiveArrayIterator($nestedArraysAndStrings)); foreach($iter as $leaf){ $flat[] = $leaf; } - return join(null, $flat); + return join('', $flat); } $noRefs = [[[['some']]],[' nested '],"items"]; diff --git a/ext/spl/tests/fixedarray_011.phpt b/ext/spl/tests/fixedarray_011.phpt deleted file mode 100644 index eddf320fcc..0000000000 --- a/ext/spl/tests/fixedarray_011.phpt +++ /dev/null @@ -1,14 +0,0 @@ ---TEST-- -SPL: FixedArray: Testing setSize() with NULL ---FILE-- -<?php - -$a = new SplFixedArray(100); - -$a->setSize(NULL); - -print "ok\n"; - -?> ---EXPECT-- -ok diff --git a/ext/spl/tests/fixedarray_014.phpt b/ext/spl/tests/fixedarray_014.phpt index a6f2fc188c..75108b5868 100644 --- a/ext/spl/tests/fixedarray_014.phpt +++ b/ext/spl/tests/fixedarray_014.phpt @@ -4,7 +4,7 @@ SPL: FixedArray: Trying to access inexistent item <?php try { - $a = new SplFixedArray(NULL); + $a = new SplFixedArray(0); echo $a[0]++; } catch (Exception $e) { echo $e->getMessage(); diff --git a/ext/spl/tests/iterator_044.phpt b/ext/spl/tests/iterator_044.phpt index 66f722af9a..74321194e0 100644 --- a/ext/spl/tests/iterator_044.phpt +++ b/ext/spl/tests/iterator_044.phpt @@ -94,8 +94,12 @@ Warning: Undefined array key "foo" in %s on line %d NULL ===3=== NULL + +Deprecated: CachingIterator::offsetExists(): Passing null to parameter #1 ($key) of type string is deprecated in %s on line %d bool(false) +Deprecated: CachingIterator::offsetGet(): Passing null to parameter #1 ($key) of type string is deprecated in %s on line %d + Warning: Undefined array key "" in %s on line %d NULL ===4=== @@ -133,8 +137,12 @@ bool(true) int(1) ===3=== NULL + +Deprecated: CachingIterator::offsetExists(): Passing null to parameter #1 ($key) of type string is deprecated in %s on line %d bool(false) +Deprecated: CachingIterator::offsetGet(): Passing null to parameter #1 ($key) of type string is deprecated in %s on line %d + Warning: Undefined array key "" in %s on line %d NULL ===4=== diff --git a/ext/spl/tests/regexIterator_flags_basic.phpt b/ext/spl/tests/regexIterator_flags_basic.phpt index 535be00035..d5b778f86b 100644 --- a/ext/spl/tests/regexIterator_flags_basic.phpt +++ b/ext/spl/tests/regexIterator_flags_basic.phpt @@ -7,7 +7,7 @@ Felix De Vliegher <felix.devliegher@gmail.com> $array = array('foo', 'bar', 'baz'); $iterator = new ArrayIterator($array); -$regexIterator = new RegexIterator($iterator, "/f/", null, RegexIterator::USE_KEY); +$regexIterator = new RegexIterator($iterator, "/f/", RegexIterator::MATCH, RegexIterator::USE_KEY); var_dump($regexIterator->getFlags() === RegexIterator::USE_KEY); |