add_006.phpt 883 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. --TEST--
  2. adding numbers to strings
  3. --INI--
  4. precision=14
  5. --FILE--
  6. <?php
  7. $i = 75636;
  8. $s1 = "this is a string";
  9. $s2 = "876222numeric";
  10. $s3 = "48474874";
  11. $s4 = "25.68";
  12. try {
  13. $c = $i + $s1;
  14. var_dump($c);
  15. } catch (\TypeError $e) {
  16. echo $e->getMessage() . \PHP_EOL;
  17. }
  18. $c = $i + $s2;
  19. var_dump($c);
  20. $c = $i + $s3;
  21. var_dump($c);
  22. $c = $i + $s4;
  23. var_dump($c);
  24. try {
  25. $c = $s1 + $i;
  26. var_dump($c);
  27. } catch (\TypeError $e) {
  28. echo $e->getMessage() . \PHP_EOL;
  29. }
  30. $c = $s2 + $i;
  31. var_dump($c);
  32. $c = $s3 + $i;
  33. var_dump($c);
  34. $c = $s4 + $i;
  35. var_dump($c);
  36. echo "Done\n";
  37. ?>
  38. --EXPECTF--
  39. Unsupported operand types: int + string
  40. Warning: A non-numeric value encountered in %s on line %d
  41. int(951858)
  42. int(48550510)
  43. float(75661.68)
  44. Unsupported operand types: string + int
  45. Warning: A non-numeric value encountered in %s on line %d
  46. int(951858)
  47. int(48550510)
  48. float(75661.68)
  49. Done