Bug #75393 [Opn->Fbk]: Value not preserved when assign-adding an array to an object

From: Date: Wed, 07 Jul 2021 12:23:09 +0000
Subject: Bug #75393 [Opn->Fbk]: Value not preserved when assign-adding an array to an object
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-234864@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=75393&edit=1 ID: 75393 Updated by: cmb@php.net Reported by: bwoebi@php.net Summary: Value not preserved when assign-adding an array to an object -Status: Open +Status: Feedback Type: Bug Package: Scripting Engine problem Operating System: Irrelevant PHP Version: 7.0Git-2017-10-16 (Git) -Assigned To: +Assigned To: cmb Block user comment: N Private report: N New Comment: This seems to be fixed as of PHP 8.0.0[1], and I don't think a backport makes much sense at this point in time. Or am I missiung something? [1] <https://3v4l.org/M8f4X> Previous Comments: ------------------------------------------------------------------------ [2019-02-14 11:27:58] nikic@php.net Triage: Segfault fixed in supported versions, but the incorrect type conversion still takes place. ------------------------------------------------------------------------ [2017-10-17 11:07:03] bwoebi@php.net Similarly: php -r 'set_error_handler(function() { throw new \Exception; }); $a = "2"; $a .= "a"; try { $a+=1; } catch (\Exception $e) { } var_dump($a);' int(3) (instead of string(2) "2a") (turns out the crash has already been fixed in the most recent git, but not yet in the last release. - renaming thus.) ------------------------------------------------------------------------ [2017-10-17 10:36:31] laruence@php.net of course I also understand why it should be an stdclass instance, it also make sense, but it will make the codes complex, and this is really a rarely wrong case, so I think choose the easy way is a good chioce here. ------------------------------------------------------------------------ [2017-10-17 10:34:08] laruence@php.net why not? <?php $o = new Stdclass(); var_dump((int)$o); output: PHP Notice: Object of class stdClass could not be converted to int in /tmp/1.php on line 3 int(1) and for: $o += [] we preparing operands first, then trying to do add, then result in unsupported operand, which seems reasonable to me ------------------------------------------------------------------------ [2017-10-17 10:15:32] bwoebi@php.net @laruence: It doesn't crash with master, yes. But it still does with PHP 7.0 and 7.1. Also $o must not be int(1), but must be an instanceof stdClass afterwards. ------------------------------------------------------------------------ The remainder of the comments for this report are too long. To view the rest of the comments, please view the bug report online at https://bugs.php.net/bug.php?id=75393 -- Edit this bug report at https://bugs.php.net/bug.php?id=75393&edit=1

« previous php.bugs (#234864) next »