Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make numeric operations on resources, arrays and objects type errors #5331

Closed
wants to merge 7 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Make numeric operations on resources, arrays and objects type errors
  • Loading branch information
nikic committed Apr 30, 2020
commit e0eb1b51ff9eb1f58dd1ea33547830324b500ea0
4 changes: 0 additions & 4 deletions Zend/tests/add_003.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,8 @@ var_dump($c);
echo "Done\n";
?>
--EXPECTF--
Notice: Object of class stdClass could not be converted to number in %sadd_003.php on line %d

Exception: Unsupported operand types: object + array

Notice: Object of class stdClass could not be converted to number in %s on line %d

Fatal error: Uncaught TypeError: Unsupported operand types: object + array in %s:%d
Stack trace:
#0 {main}
Expand Down
17 changes: 7 additions & 10 deletions Zend/tests/bug54305.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,11 @@ class TestClass {
abstract class AbstractClass {
}
$methodWithArgs = new ReflectionMethod('TestClass', 'methodWithArgs');
echo $methodWithArgs++;
?>
--EXPECTF--
Method [ <user> public method methodWithArgs ] {
@@ %sbug54305.php %d - %d

- Parameters [2] {
Parameter #0 [ <required> $a ]
Parameter #1 [ <required> $b ]
}
try {
echo $methodWithArgs++;
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
?>
--EXPECT--
Cannot increment object
5 changes: 1 addition & 4 deletions Zend/tests/bug73337.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,5 @@ Bug #73337 (try/catch not working with two exceptions inside a same operation)
class d { function __destruct() { throw new Exception; } }
try { new d + new d; } catch (Exception $e) { print "Exception properly caught\n"; }
?>
--EXPECTF--
Notice: Object of class d could not be converted to number in %sbug73337.php on line 3

Notice: Object of class d could not be converted to number in %sbug73337.php on line 3
--EXPECT--
Exception properly caught
66 changes: 33 additions & 33 deletions Zend/tests/compound_assign_failure.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -34,167 +34,167 @@ try {

$x = new stdClass;
try { $x += 1; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = 1;
try { $x += new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = "foo";
try { $x += new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = new stdClass;
try { $x -= 1; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = 1;
try { $x -= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = "foo";
try { $x -= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = new stdClass;
try { $x *= 1; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = 1;
try { $x *= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = "foo";
try { $x *= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = new stdClass;
try { $x /= 1; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = 1;
try { $x /= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = "foo";
try { $x /= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = new stdClass;
try { $x %= 1; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = 1;
try { $x %= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = "foo";
try { $x %= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = new stdClass;
try { $x **= 1; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = 1;
try { $x **= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = "foo";
try { $x **= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = new stdClass;
try { $x ^= 1; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = 1;
try { $x ^= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = "foo";
try { $x ^= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = new stdClass;
try { $x &= 1; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = 1;
try { $x &= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = "foo";
try { $x &= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = new stdClass;
try { $x |= 1; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = 1;
try { $x |= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = "foo";
try { $x |= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = new stdClass;
try { $x <<= 1; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = 1;
try { $x <<= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = "foo";
try { $x <<= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = new stdClass;
try { $x >>= 1; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = 1;
try { $x >>= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

$x = "foo";
try { $x >>= new stdClass; }
catch (Exception $e) {}
catch (Throwable $e) {}
var_dump($x);

?>
Expand Down
13 changes: 10 additions & 3 deletions Zend/tests/decrement_001_64bit.phpt
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,18 @@ $a = array(
);

foreach ($a as $var) {
$var--;
try {
$var--;
} catch (TypeError $e) {
echo $e->getMessage(), "\n";
}
var_dump($var);
}

echo "Done\n";
?>
--EXPECTF--
--EXPECT--
Cannot decrement array
array(3) {
[0]=>
int(1)
Expand All @@ -51,8 +56,10 @@ float(1.5)
NULL
bool(true)
bool(false)
object(stdClass)#%d (0) {
Cannot decrement object
object(stdClass)#1 (0) {
}
Cannot decrement array
array(0) {
}
float(-9.223372036854776E+18)
Expand Down
Loading