Guest User

php destructor exception test

a guest
Mar 27th, 2012
309
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.44 KB | None | 0 0
  1. <?php
  2. class A {
  3.   public function __construct(){
  4.     $this->i= new B();
  5.   }
  6.   public function __destruct()
  7.   {
  8.     $this->i->cleanup();
  9.   }
  10. }
  11. class B
  12. {
  13.   public function __counstruct()
  14.   {
  15.     $this->f = 5;
  16.   }
  17.   public function cleanup()
  18.   {
  19.     if(!isset($this->used)) throw new Exception('nothing to cleanup');
  20.   }
  21. }
  22. try
  23. {
  24.   $x = new A();
  25.   $x->y =5;
  26.   $x = null;
  27. }catch(Exception $e)
  28. {
  29.   echo $e->getMessage(),"\n";
  30. }
Advertisement
Add Comment
Please, Sign In to add comment