Created
May 29, 2020 14:41
-
-
Save ssi-anik/c8e98d2818227cac3f5fe6eb3409de80 to your computer and use it in GitHub Desktop.
PHP object Lifecycle.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
echo 'script 1 start' . PHP_EOL; | |
class A12 | |
{ | |
public $script = null; | |
public function __construct ($script = 's1') { | |
$this->script = $script; | |
} | |
public function __destruct () { | |
echo 'destructing a12 - ' . $this->script . PHP_EOL; | |
} | |
} | |
class B12 | |
{ | |
public $script = null; | |
public function __construct ($script = 's1') { | |
$this->script = $script; | |
} | |
public function __destruct () { | |
echo 'destructing b12 - ' . $this->script . PHP_EOL; | |
} | |
} | |
function get_a12 ($s = 's1') { | |
return new A12($s); | |
} | |
function get_b12 ($s = 's1') { | |
return new B12($s); | |
} | |
$b12 = new B12('s1'); | |
echo 'script 1 end' . PHP_EOL; | |
// script 1 ends | |
// script 2 starts | |
// <?php | |
// uncomment the following line when using multiple scripts | |
// include 'script1.php'; | |
echo 'script 2 start' . PHP_EOL; | |
$a12 = new A12('s2'); | |
echo 'script 2 end' . PHP_EOL; | |
// script 2 ends | |
// script 3 starts | |
// <?php | |
// uncomment the following line if using multiple scripts | |
// include 'script2.php'; | |
echo 'script 3 start' . PHP_EOL; | |
get_a12('s3'); | |
// comment any of the following adjucent lines, and uncomment the another one | |
get_b12('s3'); | |
// $b2 = get_b12('s3'); | |
echo 'script 3 end' . PHP_EOL; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment