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