constants_basic_001.phpt 1.6 KB

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