020.phpt 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. --TEST--
  2. FFI 020: read-only
  3. --EXTENSIONS--
  4. ffi
  5. --INI--
  6. ffi.enable=1
  7. --FILE--
  8. <?php
  9. try {
  10. $p = FFI::new("struct {int x; const int y;}");
  11. $p->x = 1;
  12. $p->y = 1;
  13. echo "ok\n";
  14. } catch (Throwable $e) {
  15. echo get_class($e) . ": " . $e->getMessage()."\n";
  16. }
  17. try {
  18. $p = FFI::new("struct {const int x; int y;}");
  19. $p->y = 1;
  20. $p->x = 1;
  21. echo "ok\n";
  22. } catch (Throwable $e) {
  23. echo get_class($e) . ": " . $e->getMessage()."\n";
  24. }
  25. try {
  26. $p = FFI::new("const struct {int x; int y;}");
  27. $p->x = 1;
  28. echo "ok\n";
  29. } catch (Throwable $e) {
  30. echo get_class($e) . ": " . $e->getMessage()."\n";
  31. }
  32. try {
  33. $p = FFI::new("const int[10]");
  34. $p[1] = 1;
  35. echo "ok\n";
  36. } catch (Throwable $e) {
  37. echo get_class($e) . ": " . $e->getMessage()."\n";
  38. }
  39. try {
  40. $p = FFI::new("const int * [1]");
  41. $p[0] = null;
  42. echo "ok\n";
  43. } catch (Throwable $e) {
  44. echo get_class($e) . ": " . $e->getMessage()."\n";
  45. }
  46. try {
  47. $p = FFI::new("int * const [1]");
  48. $p[0] = null;
  49. echo "ok\n";
  50. } catch (Throwable $e) {
  51. echo get_class($e) . ": " . $e->getMessage()."\n";
  52. }
  53. try {
  54. $f = FFI::cdef("typedef int * const t[1];");
  55. $p = $f->new("t");
  56. $p[0] = null;
  57. echo "ok\n";
  58. } catch (Throwable $e) {
  59. echo get_class($e) . ": " . $e->getMessage()."\n";
  60. }
  61. ?>
  62. ok
  63. --EXPECT--
  64. FFI\Exception: Attempt to assign read-only field 'y'
  65. FFI\Exception: Attempt to assign read-only field 'x'
  66. FFI\Exception: Attempt to assign read-only location
  67. FFI\Exception: Attempt to assign read-only location
  68. ok
  69. FFI\Exception: Attempt to assign read-only location
  70. FFI\Exception: Attempt to assign read-only location
  71. ok