Advertisement
raul3k

teste metodos magicos

May 4th, 2015
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.73 KB | None | 0 0
  1. <?php
  2. ini_set('display_errors', 1);
  3. error_reporting(E_ALL);
  4. class Teste {
  5.     function __construct()
  6.     {
  7.         echo '<br>Entrei na classe<br>';
  8.     }
  9.  
  10.     function __sleep()
  11.     {
  12.         echo '<br>Dormi<br>';
  13.         return new $this;
  14.     }
  15.  
  16.  
  17.     function __wakeup()
  18.     {
  19.         echo '<br>Acordei<br>';
  20.         return $this;
  21.     }
  22.  
  23.     function __toString()
  24.     {
  25.         return '<br>Agora sou uma string<br>';
  26.     }
  27.  
  28.     function __clone()
  29.     {
  30.         echo '<br>Tentou me clonar né?<br>';
  31.         trigger_error('Damn! Clonagem vai contra a Igreja', E_USER_ERROR);
  32.         return false;
  33.     }
  34. }
  35.  
  36.  
  37. $t = new Teste;
  38.  
  39. echo $t;
  40.  
  41. $s = (serialize($t));
  42.  
  43. var_dump(unserialize($s));
  44.  
  45. $a = clone $t;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement