negate_variationStr.phpt 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. --TEST--
  2. Test -N operator : various numbers as strings
  3. --FILE--
  4. <?php
  5. $strVals = array(
  6. "0","65","-44", "1.2", "-7.7", "abc", "123abc", "123e5", "123e5xyz", " 123abc", "123 abc", "123abc ", "3.4a",
  7. "a5.9"
  8. );
  9. foreach ($strVals as $strVal) {
  10. echo "--- testing: '$strVal' ---\n";
  11. try {
  12. var_dump(-$strVal);
  13. } catch (\TypeError $e) {
  14. echo $e->getMessage() . \PHP_EOL;
  15. }
  16. }
  17. ?>
  18. --EXPECTF--
  19. --- testing: '0' ---
  20. int(0)
  21. --- testing: '65' ---
  22. int(-65)
  23. --- testing: '-44' ---
  24. int(44)
  25. --- testing: '1.2' ---
  26. float(-1.2)
  27. --- testing: '-7.7' ---
  28. float(7.7)
  29. --- testing: 'abc' ---
  30. Unsupported operand types: string * int
  31. --- testing: '123abc' ---
  32. Warning: A non-numeric value encountered in %s on line %d
  33. int(-123)
  34. --- testing: '123e5' ---
  35. float(-12300000)
  36. --- testing: '123e5xyz' ---
  37. Warning: A non-numeric value encountered in %s on line %d
  38. float(-12300000)
  39. --- testing: ' 123abc' ---
  40. Warning: A non-numeric value encountered in %s on line %d
  41. int(-123)
  42. --- testing: '123 abc' ---
  43. Warning: A non-numeric value encountered in %s on line %d
  44. int(-123)
  45. --- testing: '123abc ' ---
  46. Warning: A non-numeric value encountered in %s on line %d
  47. int(-123)
  48. --- testing: '3.4a' ---
  49. Warning: A non-numeric value encountered in %s on line %d
  50. float(-3.4)
  51. --- testing: 'a5.9' ---
  52. Unsupported operand types: string * int