Last active
February 7, 2017 14:28
-
-
Save shov/d8536e37f6cc3e71ea3a76bdb21a0365 to your computer and use it in GitHub Desktop.
This file contains 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 | |
class DB | |
{ | |
public function burn(string $data) | |
{ | |
if(empty($data)) throw new \Exception(sprintf("Wrong data, %s given" . PHP_EOL, $data)); | |
echo $data . PHP_EOL; | |
} | |
} | |
global $db; | |
$db = new DB(); | |
class GoodDayToDie | |
{ | |
protected $data; | |
public function __construct() | |
{ | |
$this->data = [ | |
'good data', | |
'0', | |
new \stdClass(), | |
42, | |
]; | |
} | |
public function test() | |
{ | |
global $db; | |
foreach ($this->data as $val) { | |
try { | |
$db->burn($val); | |
} catch(\Exception $e) { | |
echo $e->getMessage(); | |
} catch (\Error $e) { | |
echo "Error!" . PHP_EOL; | |
} | |
} | |
} | |
public function __destruct() | |
{ | |
global $db; | |
foreach ($this->data as $val) { | |
try { | |
$db->burn($val); | |
} catch(\Exception $e) { | |
echo $e->getMessage(); | |
} catch (\Error $e) { | |
echo "Error!" . PHP_EOL; | |
} | |
} | |
} | |
} | |
for($i = 0; $i < 1000; $i++) { | |
$test = new GoodDayToDie(); | |
$test->test(); | |
$test = null; | |
} |
Author
shov
commented
Feb 7, 2017
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment