3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php error_reporting(0); function testBinaryOperators() { $asserts = [ INativeType::TYPE_INT => [ function () { (false || $a) instanceof $a; }, function () { 1 + 1; }, function () { 1 - 1; }, function () { 1 * 1; }, function () { 1 & 1; }, function () { '' & 1; }, function () { 1 | 1; }, function () { '' | 1; }, function () { 1 << 1; }, function () { 1.0 << 1; }, function () { 1 >> 1; }, function () { 1 >> 1.0; }, function () { 1 ^ 1; }, function () { 1 ^ 1.0; }, function () { 1.0 ^ 1.0; }, ], INativeType::TYPE_DOUBLE => [ function () { 1 + 1.0; }, function () { 1.0 + 1; }, function () { 1.0 + 1.0; }, function () { 1 - 1.0; }, function () { 1.0 - 1; }, function () { 1.0 - 1.0; }, function () { 1 * 1.0; }, function () { 1.0 * 1; }, function () { 1.0 * 1.0; }, function () { 3.4 / 24; }, function () { 34 / 2.4; }, function () { 3.4 / 2.34; }, ], INativeType::TYPE_BOOL => [ function () { 1 && 1.0; }, function () { 1 && 0; }, function () { true && 0; }, function () { 0 && true; }, function () { false && true; }, function () { '' && true; }, function () { false && ''; }, function () { 2.3 && true; }, function () { false && 2.1; }, function () { [] && true; }, function () { false && [1,2]; }, function () { 1 || 1.0; }, function () { 1 || 0; }, function () { true || 0; }, function () { 0 || true; }, function () { false || true; }, function () { '' || true; }, function () { false || ''; }, function () { 2.3 || true; }, function () { false || 2.1; }, function () { [] || true; }, function () { false || [1,2]; }, function () { 3 < 3; }, function () { 3 < 3.0; }, function () { 3 < '3'; }, function () { 3 <= 3; }, function () { 3 <= '3'; }, function () { 3.0 <= 3; }, function () { 3 > 3; }, function () { 3.0 > 3; }, function () { 3 > '3'; }, function () { 3 > 3.0; }, function () { 3.0 >= 3; }, function () { 3 >= 3.0; }, function () { 3 >= '3'; }, ], INativeType::TYPE_ARRAY => [ function () { [] + [1,2]; }, function () { [] + [1,2,3] + [2] + ['abc']; }, ], INativeType::TYPE_STRING => [ function () { 'abc' . '123'; }, function () { 'abc' . 123; }, function () { 'abc' . 123.42; }, function () { 123 . 'ab'; }, function () { 123.42 . 'a'; }, function () { 2 . 3.45; }, function () { false . ''; }, function () { '' . true; }, function () { false . true; }, function () { false . 3.2; }, function () { 3 . 9; }, ], INativeType::TYPE_MIXED => [ function () { '123' + 1; }, function () { '123' - 1; }, function () { '123' * 1; }, function () { '123' + 1; }, function () { 3 + 'av1'; }, function () { 3 - 'av1'; }, function () { 3 * 'av1'; }, @function () { 3 / ('av1' . $a); }, @function () { 'as' + 'av1'; }, function () { 1 / 2; }, function () { 1 / 1; }, function () { '123' / 24; }, ], ]; foreach($asserts as $expectedType => $expressions) { foreach($expressions as $expression) { $this->assertReturnsNativeType($expression, $expectedType); } } }
based on 48fUc
Output for 5.4.0 - 7.2.0