bug-gh8471.phpt 1.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. --TEST--
  2. Bug GH-8471: Segmentation fault when converting immutable and mutable DateTime instances created using reflection
  3. --FILE--
  4. <?php
  5. $reflection = new ReflectionClass('\DateTime');
  6. $mutable = $reflection->newInstanceWithoutConstructor();
  7. try {
  8. $immutable = \DateTimeImmutable::createFromMutable($mutable);
  9. } catch (Throwable $t) {
  10. echo $t->getMessage(), "\n";
  11. }
  12. $reflection = new ReflectionClass('\DateTime');
  13. $mutable = $reflection->newInstanceWithoutConstructor();
  14. try {
  15. $immutable = \DateTimeImmutable::createFromInterface($mutable);
  16. } catch (Throwable $t) {
  17. echo $t->getMessage(), "\n";
  18. }
  19. $reflection = new ReflectionClass('\DateTimeImmutable');
  20. $immutable = $reflection->newInstanceWithoutConstructor();
  21. try {
  22. $mutable = \DateTime::createFromImmutable($immutable);
  23. } catch (Throwable $t) {
  24. echo $t->getMessage(), "\n";
  25. }
  26. $reflection = new ReflectionClass('\DateTimeImmutable');
  27. $immutable = $reflection->newInstanceWithoutConstructor();
  28. try {
  29. $mutable = \DateTime::createFromInterface($immutable);
  30. } catch (Throwable $t) {
  31. echo $t->getMessage(), "\n";
  32. }
  33. ?>
  34. --EXPECTF--
  35. The DateTime object has not been correctly initialized by its constructor
  36. The DateTimeInterface object has not been correctly initialized by its constructor
  37. The DateTimeImmutable object has not been correctly initialized by its constructor
  38. The DateTimeInterface object has not been correctly initialized by its constructor