exception_from_toString.phpt 755 B

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. --TEST--
  2. Check that exceptions from __toString() are handled correctly
  3. --EXTENSIONS--
  4. sqlite3
  5. --FILE--
  6. <?php
  7. class throws {
  8. function __toString() {
  9. throw new Exception("Sorry");
  10. }
  11. }
  12. $db = new sqlite3(':memory:');
  13. $db->exec('CREATE TABLE t(id int, v varchar(255))');
  14. $stmt = $db->prepare('INSERT INTO t VALUES(:i, :v)');
  15. $stmt->bindValue('i', 1234);
  16. $stmt->bindValue('v', new throws);
  17. try {
  18. $stmt->execute();
  19. } catch (Exception $e) {
  20. echo "Exception thrown ...\n";
  21. }
  22. try {
  23. $stmt->execute();
  24. } catch (Exception $e) {
  25. echo "Exception thrown ...\n";
  26. }
  27. $query = $db->query("SELECT * FROM t");
  28. while ($row = $query->fetchArray(SQLITE3_ASSOC)) {
  29. print_r($row);
  30. }
  31. ?>
  32. --EXPECT--
  33. Exception thrown ...
  34. Exception thrown ...