[php-src] Issue #15968: BCMath\Number operators may typecast operand
| From: | cmb69 | Date: | Fri, 20 Sep 2024 21:28:28 +0000 |
| Subject: | [php-src] Issue #15968: BCMath\Number operators may typecast operand | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-247840@lists.php.net to get a copy of this message | ||
Issue: https://github.com/php/php-src/issues/15968
Author: cmb69
### Description
The following code:
```php
<?php
class MyString {
function __toString() {
return "2";
}
}
$a = new BCMath\Number("1");
$b = new MyString();
var_dump($a + $b, $b);
```
Resulted in this output:
```
object(BcMath\Number)#2 (2) {
["value"]=>
string(1) "3"
["scale"]=>
int(0)
}
string(1) "2"
```
But I expected this output instead:
```
object(BcMath\Number)#2 (2) {
["value"]=>
string(1) "3"
["scale"]=>
int(0)
}
object(MyString)#2 (0) {
}
```
Note that this even happens in strict typing mode, where it may not even be expected that the
addition succeeds.
Anyhow, the problem is that
zend_parse_arg_str_or_long_slow() converts the passed
arg.
Also note that GMP also uses ZPP functionality, but catches any such type conversion, even in
coercive typing mode.
### PHP Version
PHP 8.4
### Operating System
any