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 :: model all 
Php :: laravel rename file ftp 
Php :: laravel error not responding well 
Php :: Laravel model - CRUD only with records where one column = certain value 
Php :: Laravel Retrieving Session Data 
Php :: sort names alphabetically php 
Php :: remove public from laravel 8 url 
Php :: update php version of particular domain on ubuntu 
Php :: convert php to curl 
Php :: count same datetimes in foreach and group them php 
Php :: Parameters inside Laravel localized string 
Php :: php find odd even number in loop 
Php :: flask like framework for php 
Php :: print csv file in php 
Php :: php strip period 
Php :: add column in exesting table 
Php :: Drupal get node id from view 
Php :: oneliner if php 
Php :: at C:UsersKamyarweb-pages elebotvendorsymfonyprocessPipesWindowsPipes.php:63 laravel error 
Php :: ajax call php bootstrap validation 
Php :: wordpress deny user to access wp-admin programmatically 
Php :: examples of invalid php variables 
Php :: php if 2 files in dir unlink the olderst 
Php :: Best version control tools for php 
Php :: yii2 has many where 
Php :: connexion sql php/html 
Php :: how to remove copyright footer from xenforo 2 
Php :: how to concatenate folder name with image in php 
Php :: PHP strncasecmp — Binary safe case-insensitive string comparison of the first n characters 
Php :: laravel project preparation,laravel project create 
ADD CONTENT
Topic
Content
Source link
Name
4+5 =