php-src/ext/gmp/tests/overloading_with_object_stringable.phpt
Gina Peter Banyard 5253647500
ext/gmp: Fix segfault when null is encountered on an overloaded operator
And various other issues like inconsistent type errors

Closes GH-16015
2024-11-02 17:36:32 +00:00

91 lines
2 KiB
PHP

--TEST--
GMP operator overloading does not support stringable objects
--EXTENSIONS--
gmp
--FILE--
<?php
class T {
public function __toString() {
return "42";
}
}
$num = gmp_init(42);
$o = new T();
try {
var_dump($num + $o);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump($num - $o);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump($num * $o);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump($num / $o);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump($num % $o);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump($num ** $o);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump($num | $o);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump($num & $o);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump($num ^ $o);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump($num << $o);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
try {
var_dump($num >> $o);
} catch (Throwable $e) {
echo $e::class, ': ', $e->getMessage(), PHP_EOL;
}
?>
--EXPECTF--
TypeError: Number must be of type GMP|string|int, T given
TypeError: Number must be of type GMP|string|int, T given
TypeError: Number must be of type GMP|string|int, T given
TypeError: Number must be of type GMP|string|int, T given
TypeError: Number must be of type GMP|string|int, T given
TypeError: Unsupported operand types: GMP ** T
TypeError: Number must be of type GMP|string|int, T given
TypeError: Number must be of type GMP|string|int, T given
TypeError: Number must be of type GMP|string|int, T given
TypeError: Unsupported operand types: GMP << T
TypeError: Unsupported operand types: GMP >> T