constants_basic_001.phpt 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. --TEST--
  2. Class constant declarations
  3. --FILE--
  4. <?php
  5. define('DEFINED', 1234);
  6. $def = 456;
  7. define('DEFINED_TO_VAR', $def);
  8. define('DEFINED_TO_UNDEF_VAR', $undef);
  9. class C
  10. {
  11. const c0 = UNDEFINED;
  12. const c1 = 1, c2 = 1.5;
  13. const c3 = + 1, c4 = + 1.5;
  14. const c5 = -1, c6 = -1.5;
  15. const c7 = __LINE__;
  16. const c8 = __FILE__;
  17. const c9 = __CLASS__;
  18. const c10 = __METHOD__;
  19. const c11 = __FUNCTION__;
  20. const c12 = DEFINED;
  21. const c13 = DEFINED_TO_VAR;
  22. const c14 = DEFINED_TO_UNDEF_VAR;
  23. const c15 = "hello1";
  24. const c16 = 'hello2';
  25. const c17 = C::c16;
  26. const c18 = self::c17;
  27. }
  28. echo "\nAttempt to access various kinds of class constants:\n";
  29. var_dump(C::c0);
  30. var_dump(C::c1);
  31. var_dump(C::c2);
  32. var_dump(C::c3);
  33. var_dump(C::c4);
  34. var_dump(C::c5);
  35. var_dump(C::c6);
  36. var_dump(C::c7);
  37. var_dump(C::c8);
  38. var_dump(C::c9);
  39. var_dump(C::c10);
  40. var_dump(C::c11);
  41. var_dump(C::c12);
  42. var_dump(C::c13);
  43. var_dump(C::c14);
  44. var_dump(C::c15);
  45. var_dump(C::c16);
  46. var_dump(C::c17);
  47. var_dump(C::c18);
  48. echo "\nExpecting fatal error:\n";
  49. var_dump(C::c19);
  50. echo "\nYou should not see this.";
  51. ?>
  52. --EXPECTF--
  53. Notice: Undefined variable: undef in %s on line 5
  54. Attempt to access various kinds of class constants:
  55. Notice: Use of undefined constant UNDEFINED - assumed 'UNDEFINED' in %s on line %d
  56. string(9) "UNDEFINED"
  57. int(1)
  58. float(1.5)
  59. int(1)
  60. float(1.5)
  61. int(-1)
  62. float(-1.5)
  63. int(15)
  64. string(%d) "%s"
  65. string(1) "C"
  66. string(1) "C"
  67. string(0) ""
  68. int(1234)
  69. int(456)
  70. NULL
  71. string(6) "hello1"
  72. string(6) "hello2"
  73. string(6) "hello2"
  74. string(6) "hello2"
  75. Expecting fatal error:
  76. Fatal error: Undefined class constant 'c19' in %s on line 53