uniqid_basic.phpt 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. --TEST--
  2. Test uniqid() function : basic functionality
  3. --FILE--
  4. <?php
  5. /* Prototype : string uniqid ([ string $prefix= "" [, bool $more_entropy= false ]] )
  6. * Description: Gets a prefixed unique identifier based on the current time in microseconds.
  7. * Source code: ext/standard/uniqid.c
  8. */
  9. echo "*** Testing uniqid() : basic functionality ***\n";
  10. echo "\nuniqid() without a prefix\n";
  11. var_dump(uniqid());
  12. var_dump(uniqid(null, true));
  13. var_dump(uniqid(null, false));
  14. echo "\n\n";
  15. echo "uniqid() with a prefix\n";
  16. // Use a fixed prefix so we can ensure length of o/p id is fixed
  17. $prefix = array (
  18. 99999,
  19. "99999",
  20. 10.5e2,
  21. null,
  22. true,
  23. false
  24. );
  25. for ($i = 0; $i < count($prefix); $i++) {
  26. var_dump(uniqid($prefix[$i]));
  27. var_dump(uniqid($prefix[$i], true));
  28. var_dump(uniqid($prefix[$i], false));
  29. echo "\n";
  30. }
  31. ?>
  32. ===DONE===
  33. --EXPECTF--
  34. *** Testing uniqid() : basic functionality ***
  35. uniqid() without a prefix
  36. string(13) "%s"
  37. string(23) "%s.%s"
  38. string(13) "%s"
  39. uniqid() with a prefix
  40. string(18) "99999%s"
  41. string(28) "99999%s.%s"
  42. string(18) "99999%s"
  43. string(18) "99999%s"
  44. string(28) "99999%s.%s"
  45. string(18) "99999%s"
  46. string(17) "1050%s"
  47. string(27) "1050%s.%s"
  48. string(17) "1050%s"
  49. string(13) "%s"
  50. string(23) "%s.%s"
  51. string(13) "%s"
  52. string(14) "1%s"
  53. string(24) "1%s.%s"
  54. string(14) "1%s"
  55. string(13) "%s"
  56. string(23) "%s.%s"
  57. string(13) "%s"
  58. ===DONE===