23 Program to demonstrate Serialization in PHP

Program:
<?php

    class Customer

    {

        private $name;

        private $credit;

       

        public function __construct($name,$credit)

        {

            $this->name = $name;

            $this->credit = $credit;

        }

       

        public function __sleep()

        {

            echo "Sleep Calling <br><br>";

            return array('name','credit');

        }

       

        public function __wakeup()

        {

            echo "WakeUp Calling <br><br>";

        }

    }



    $c = new Customer("Atharva",1234567);

    $data = serialize($c);

    echo "$data <br><br>";

    print_r(unserialize($data));

   

?>


Output:

Program to demonstrate Serialization in PHP

Previous
Next Post »