Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes bug 75268. The design is that all string keys must come before all integer keys. The string keys become properties and the integer keys become values in the array. Other serialization/unserialization methods should adopt this same strategy as there are bugs: https://3v4l.org/IMnI5 Migrate SplFixedArray to get_properties_for. Extract spl_fixedarray_import, as I expect to reuse this code for other cases as well, such as the serialization bug mentioned above.
- Loading branch information
1 parent
1079622
commit 6b90914
Showing
6 changed files
with
288 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 2 additions & 0 deletions
2
ext/spl/tests/ArrayObject_overloaded_object_incompatible.phpt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
--TEST-- | ||
SplFixedArray: __set_state | ||
--FILE-- | ||
<?php | ||
|
||
$fixed = SplFixedArray::__set_state([1, 2, 3]); | ||
var_export($fixed); | ||
echo "\n---\n"; | ||
|
||
// dynamic properties | ||
$fixed->undefined = 'undef'; | ||
var_export($fixed); | ||
echo "\n---\n"; | ||
|
||
// inheritance | ||
class Vec | ||
extends SplFixedArray | ||
{ | ||
public $type; | ||
} | ||
$vec = new Vec(3); | ||
$vec[0] = 1; | ||
$vec[1] = 2; | ||
$vec[2] = 3; | ||
$vec->type = 'int'; | ||
var_export($vec); | ||
echo "\n---\n"; | ||
|
||
/* todo: check that __set_state returns "static" | ||
$method = new ReflectionMethod('SplFixedArray', '__set_state'); | ||
assert($method->hasReturnType()); | ||
$type = (string) $method->getReturnType(); | ||
var_dump($type); | ||
*/ | ||
|
||
?> | ||
--EXPECT-- | ||
SplFixedArray::__set_state(array( | ||
0 => 1, | ||
1 => 2, | ||
2 => 3, | ||
)) | ||
--- | ||
SplFixedArray::__set_state(array( | ||
'undefined' => 'undef', | ||
0 => 1, | ||
1 => 2, | ||
2 => 3, | ||
)) | ||
--- | ||
Vec::__set_state(array( | ||
'type' => 'int', | ||
0 => 1, | ||
1 => 2, | ||
2 => 3, | ||
)) | ||
--- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
--TEST-- | ||
SplFixedArray: __set_state | ||
--FILE-- | ||
<?php | ||
|
||
try { | ||
$fixed = SplFixedArray::__set_state([1 => 2]); | ||
} catch (ValueError $error) { | ||
var_dump($error->getMessage()); | ||
} | ||
|
||
try { | ||
$fixed = SplFixedArray::__set_state([0 => 1, 1 => 2, 3 => 4]); | ||
} catch (ValueError $error) { | ||
var_dump($error->getMessage()); | ||
} | ||
|
||
try { | ||
$fixed = SplFixedArray::__set_state([-1 => 2]); | ||
} catch (ValueError $error) { | ||
var_dump($error->getMessage()); | ||
} | ||
|
||
echo "-----\n"; | ||
|
||
try { | ||
$fixed = SplFixedArray::__set_state([0 => 1, 'type' => 'undefined']); | ||
} catch (ValueError $error) { | ||
var_dump($error->getMessage()); | ||
} | ||
--EXPECTF-- | ||
string(%d) "SplFixedArray::__set_state(): Argument #1 ($state) did not have integer keys that start at 0 and increment sequentially" | ||
string(%d) "SplFixedArray::__set_state(): Argument #1 ($state) did not have integer keys that start at 0 and increment sequentially" | ||
string(%d) "SplFixedArray::__set_state(): Argument #1 ($state) did not have integer keys that start at 0 and increment sequentially" | ||
----- | ||
string(%d) "SplFixedArray::__set_state(): Argument #1 ($state) must have all its string keys come before all integer keys" |