Search
 
SCRIPT & CODE EXAMPLE
 

PHP

public function __sleep() and __wakeup()

class demoSleepWakeup {
    public $resourceM;
    public $arrayM;

    public function __construct() {
        $this->resourceM = fopen("demo.txt", "w");
        $this->arrayM = array(1, 2, 3, 4); // Enter code here
    }

    public function __sleep() {
        return array('arrayM');
    }

    public function __wakeup() {
        $this->resourceM = fopen("demo.txt", "w");
    }
}

$obj = new demoSleepWakeup();
$serializedStr = serialize($obj);
var_dump($obj);
var_dump($serializedStr);
var_dump(unserialize($serializedStr));
Comment

__sleep and __wakeup

<?php
 
class Dormeur {
 
  /**
   * Méthode magique __sleep() Appelée lors d’un serialize()
   * 
   * @return Array la liste des paramètres à conserver
   */
  public function __sleep() {
    echo 'Bon ben moi, je vais dormir.';
    return array('_age','_aSonBonnet','_couleurPreferee');
  }
 
  /**
   * Méthode magique __wakeup() Appelée lors d’un unserialize()
   * 
   * @return void
   */
  public function __wakeup() {
    echo 'bon ben moi, je vais me faire un café.';
  }
}
?>
Comment

PREVIOUS NEXT
Code Example
Php :: php getgmail name 
Php :: leaf php 
Php :: where clause with paginate laravel multiple column 
Php :: Combining AND, OR and NOT 
Php :: Pasar el email de recuperar contraseña de laravel a español 
Php :: laravel pass multipale provider 
Php :: ajax php example 
Php :: how to check if a user sent you money in paypal in php 
Php :: split php 
Php :: laravel components 
Php :: spatie media library 
Php :: php string filter email 
Php :: how to get the ip address of the client in php 
Php :: php send values in $_SESSION to other page 
Php :: php catch mysqli_connect(): (HY000/1045): Access denied 
Php :: laravel validation alphanumeric with spaces 
Php :: Attempt to read property "name" on bool 
Php :: get all weeks in month php 
Php :: php izyboy 
Java :: import android.support.v7.app.appcompatactivity error 
Java :: spring jpa repository gradle 
Java :: java read file to string 
Java :: java integer to binary string with leading zeros 
Java :: convert string to float java 
Java :: hello word java 
Java :: android java remove imageview source 
Java :: converting string to int java 
Java :: import androidx.core.util.ArraySet; ^ symbol: class ArraySet location: package androidx.core.util 
Java :: internet permission in android studio 
Java :: icon button java 
ADD CONTENT
Topic
Content
Source link
Name
5+2 =