Challenge: Serialize and Unserialize Different Data Structures
A hands-on exercise to test your knowledge of the new PHP 8’s backward-compatibility break.
This challenge will extensively test our concepts regarding the new PHP 8’s backward compatibility break. We will use these concepts to use the serialization and unserialization process for different types of data structures, including ArrayObject
, ArrayIterator
, SplDoublyLinkedList
, and SplObjectStorage
.
Task 1
Implement a PHP 8 Script that initializes an
ArrayObject
with two keys.Serialize the
ArrayObject
.Unserialize the serialized array to recreate the original array.
Iterate over the array using a loop.
Display the contents of the array during the iteration.
Instructions
Following are the instructions to perform this task.
Create an
ArrayObject
with two keys,name
andage
. TheArrayObject
is then serialized and unserialized, and the values of the keys are accessed using array notation.Create an
ArrayIterator
and the iterator is used to loop through the keys and values of theArrayObject
, printing each key-value pair to the console.
Coding playground
Attempt the challenge in the coding playground below. Good luck!
Get hands-on with 1400+ tech skills courses.