fork download
  1. <?php
  2.  
  3. class Connection
  4. {
  5. public function __construct(array $data)
  6. {
  7. if (isset($data['a'], $data['b'], $data['c'])) {
  8. echo "OK".PHP_EOL;
  9. } else {
  10. throw new Exception("Some big error");
  11. }
  12. }
  13.  
  14. public function printVar($var)
  15. {
  16. echo $var.PHP_EOL;
  17. }
  18. }
  19.  
  20. class BlogPost {
  21.  
  22. public function __construct(array $data)
  23. {
  24. try {
  25. $this->db = new Connection($data);
  26. $this->db->printVar('Hello world');
  27. } catch (Exception $e) {
  28. exit($e->getMessage().PHP_EOL);
  29. }
  30. }
  31. }
  32.  
  33. $post1 = new BlogPost(array('a' => 'a', 'b' => 'b', 'c' => 'c')); // will work
  34. $post2 = new BlogPost(array('a' => 'a', 'b' => 'b')); // will fail
  35.  
Success #stdin #stdout 0.01s 20568KB
stdin
Standard input is empty
stdout
OK
Hello world
Some big error