Skip to content

Unable to resize SplfixedArray after being unserialized in PHP 8.2.15 #13531

Closed

Description

@codex-m

Description

The following code:

<?php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
ini_set('error_reporting', E_ALL);

echo "============" . "<br />";
echo "Testing in " . phpversion() . "<br />";
echo "============";
echo "<br /><br />";

/**
 * Create 5 items
 */
$array = new SplFixedArray(5);

/**
 * Get size
 * EXPECTED: 5
 */
$size = $array->getSize();
echo "Original size before serializing. Expected result is 5." . "<br />";
echo "Actual result: $size";
echo "<br /><br />";

/**
 * Serialize SPLFixedArray object
 */
$serialized = serialize($array);

/**
 * Unserialize SPLFixedArray object
 */
$array = unserialize($serialized);

/**
 * Get size
 * EXPECTED: 5
 */
$size = $array->getSize();
echo "Original size after serializing. Expected is still 5." . "<br />";
echo "Actual result is $size";
echo "<br /><br />";
   
/**
 * Resize SPLFixedArray to 6 items
 */
echo "Resizing array to 6 items" . "<br />";
$array->setSize(6);
/**
 * Get size after resize
 * EXPECTED: 6
 */
$size = $array->getSize();
echo "Updated size after resize. " . "<em>" . "Expected is 6." . "</em>" . "<br />";
echo "<strong>" . "Actual result is $size" . "</strong>";
echo "<br />";

Resulted in this output:

============
Testing in 8.2.15
============

Original size before serializing. Expected result is 5.
Actual result: 5

Original size after serializing. Expected is still 5.
Actual result is 5

Resizing array to 6 items
Updated size after resize. Expected is 6.
Actual result is 5

But I expected this output instead:

============
Testing in 8.2.15
============

Original size before serializing. Expected result is 5.
Actual result: 5

Original size after serializing. Expected is still 5.
Actual result is 5

Resizing array to 6 items
Updated size after resize. Expected is 6.
Actual result is 6

Additional notes:

  • This is only reproducible with PHP 8.2.15.
  • It works well with PHP 8.1/8.0/7.4.

I've checked the docs on changes with setSize() method with PHP 8.2. It does not mention that it cannot be used after unserializing. So I open this ticket as it could be a bug. Thank you!

PHP Version

PHP 8.2.15

Operating System

Ubuntu 22.04 LTS

Activity

  1. self-assigned this
    on Feb 27, 2024
  2. added a commit that references this issue on Feb 27, 2024
    066e0ac
  3. added a commit that references this issue on Feb 27, 2024
    8494058
  4. added 2 commits that reference this issue on Feb 27, 2024
    0285395
    1d20fc5
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions