cast_to_int.phpt 634 B

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