cast_to_double.phpt 687 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. --TEST--
  2. casting different variables to double
  3. --INI--
  4. precision=14
  5. --FILE--
  6. <?php
  7. $r = fopen(__FILE__, "r");
  8. class test {
  9. function __toString() {
  10. return "10";
  11. }
  12. }
  13. $o = new test;
  14. $vars = array(
  15. "string",
  16. "8754456",
  17. "",
  18. "\0",
  19. 9876545,
  20. 0.10,
  21. array(),
  22. array(1,2,3),
  23. false,
  24. true,
  25. NULL,
  26. $r,
  27. $o
  28. );
  29. foreach ($vars as $var) {
  30. $tmp = (double)$var;
  31. var_dump($tmp);
  32. }
  33. echo "Done\n";
  34. ?>
  35. --EXPECTF--
  36. float(0)
  37. float(8754456)
  38. float(0)
  39. float(0)
  40. float(9876545)
  41. float(0.1)
  42. float(0)
  43. float(1)
  44. float(0)
  45. float(1)
  46. float(0)
  47. float(%f)
  48. Warning: Object of class test could not be converted to float in %s on line %d
  49. float(1)
  50. Done