[ create a new paste ] login | about

Link: http://codepad.org/os8qP6ml    [ raw code | output | fork ]

PHP, pasted on Dec 19:
<?php

class A
{
	public function __construct() { var_dump('Creating: '. get_class($this)); }
	public function __destruct() { var_dump('Removing: '. get_class($this)); }
}

class B extends A {}

$A = new A();

/*
 * When this block is called later on
 */
function create_b()
{
	$B = new B();
} // At this point the function ends, and since $B is not used anymore it's removed.


var_dump('B is next');
create_b(); // Run above block, create, then destroy be
var_dump('B is now gone');

// At this point the PHP file parser ends, $A is destroyed since it's not used anymore


Output:
1
2
3
4
5
6
string(11) "Creating: A"
string(9) "B is next"
string(11) "Creating: B"
string(11) "Removing: B"
string(13) "B is now gone"
string(11) "Removing: A"


Create a new paste based on this one


Comments: