bug78624.phpt 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. --TEST--
  2. Test session_set_save_handler() : session_gc() returns the number of deleted records.
  3. --INI--
  4. session.name=PHPSESSID
  5. session.save_handler=files
  6. session.gc_probability=0
  7. --EXTENSIONS--
  8. session
  9. --SKIPIF--
  10. <?php include('skipif.inc'); ?>
  11. --FILE--
  12. <?php
  13. ob_start();
  14. echo "*** Test session_set_save_handler() : session_gc() returns the number of deleted records. ***\n";
  15. class MySession implements SessionHandlerInterface {
  16. public function open($path, $name): bool {
  17. echo 'Open', "\n";
  18. return true;
  19. }
  20. public function read($key): string|false {
  21. echo 'Read ', session_id(), "\n";
  22. return '';
  23. }
  24. public function write($key, $data): bool {
  25. echo 'Write ', session_id(), "\n";
  26. return true;
  27. }
  28. public function close(): bool {
  29. echo 'Close ', session_id(), "\n";
  30. return true;
  31. }
  32. public function destroy($key): bool {
  33. echo 'Destroy ', session_id(), "\n";
  34. return true;
  35. }
  36. public function gc($ts): int|false {
  37. echo 'Garbage collect', "\n";
  38. return 1;
  39. }
  40. }
  41. $handler = new MySession;
  42. session_set_save_handler($handler);
  43. session_start();
  44. var_dump(session_gc());
  45. session_write_close();
  46. ?>
  47. --EXPECTF--
  48. *** Test session_set_save_handler() : session_gc() returns the number of deleted records. ***
  49. Open
  50. Read %s
  51. Garbage collect
  52. int(1)
  53. Write %s
  54. Close %s