gh9583-extra.phpt 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. --TEST--
  2. GH-9583: session_create_id() fails with user defined save handler that doesn't have a validateId() method
  3. --EXTENSIONS--
  4. session
  5. --SKIPIF--
  6. <?php include('skipif.inc'); ?>
  7. --FILE--
  8. <?php
  9. class SessionHandlerTester implements \SessionHandlerInterface
  10. {
  11. public function close(): bool { return true; }
  12. public function destroy($id): bool { return true; }
  13. public function gc($max_lifetime): int|false { return 1; }
  14. public function open($path, $name): bool { return true; }
  15. public function read($id): string { return ''; }
  16. public function write($id, $data): bool { return true; }
  17. //public function create_sid() { return uniqid(); }
  18. //public function validateId($key) { return true; }
  19. }
  20. $obj = new SessionHandlerTester();
  21. ini_set('session.use_strict_mode','1');
  22. session_set_save_handler($obj);
  23. session_start();
  24. $originalSessionId = session_id();
  25. session_write_close();
  26. session_start();
  27. $newSessionId = session_id();
  28. echo 'validateId() ', (method_exists($obj, 'validateId') ? ('returns ' . ($obj->validateId(1) ? 'true' : 'false')) : 'is commented out'), "\n";
  29. var_dump($originalSessionId == $newSessionId);
  30. ?>
  31. --EXPECT--
  32. validateId() is commented out
  33. bool(true)