Skip to content

Instantly share code, notes, and snippets.

@shov
Last active February 7, 2017 14:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shov/d8536e37f6cc3e71ea3a76bdb21a0365 to your computer and use it in GitHub Desktop.
Save shov/d8536e37f6cc3e71ea3a76bdb21a0365 to your computer and use it in GitHub Desktop.
<?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;
}
@shov
Copy link
Author

shov commented Feb 7, 2017

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment