Bug #78667 [NEW]: Segmentation fault when using clone in jsonSerilization method
| From: | aparcos at gmail dot com | Date: | Sat, 12 Oct 2019 21:44:49 +0000 |
| Subject: | Bug #78667 [NEW]: Segmentation fault when using clone in jsonSerilization method | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-223188@lists.php.net to get a copy of this message | ||
From: aparcos at gmail dot com
Operating system: Debian 10
PHP version: Irrelevant
Package: Class/Object related
Bug Type: Bug
Bug description:Segmentation fault when using clone in jsonSerilization method
Description:
------------
A segmentation fault is going to happen when you accidentally uses clone
inside the jsonSerialize method that implements JsonSerializable and
return the new cloned object. If you uncomment the following test
script, you will see that is going to be called several times until the
recursive call get exhausted and finish given the segmentation fault.
Test script:
---------------
<?php
class CloneThis implements JsonSerializable {
public $date;
public function jsonSerialize() {
$clone = clone $this;
// var_dump($this);
// if ($this->date instanceof DateTime) {
// $clone->date = $this->date->format('Y.m.d');
// }
return $clone;
}
}
$variable = new CloneThis;
$variable->date = new DateTime();
echo json_encode($variable);
Expected result:
----------------
I think should be :
1. or the current date.
2. or An error where many recursive calls are done (maybe)
Actual result:
--------------
////////////////////////////////
...strings removed
object(CloneThis)#52273 (1) {
["date"]=>
string(10) "2019.10.12"
}
object(CloneThis)#52274 (1) {
["date"]=>
string(10) "2019.10.12"
}
object(CloneThis)#52275 (1) {
["date"]=>
string(10) "2019.10.12"
}
object(CloneThis)#52276 (1) {
["date"]=>
string(10) "2019.10.12"
}
object(CloneThis)#52277 (1) {
["date"]=>
Segment violation
--
Edit bug report at https://bugs.php.net/bug.php?id=78667&edit=1
--
Fix committed: https://bugs.php.net/fix.php?id=78667&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=78667&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=78667&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=78667&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=78667&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=78667&r=support
Expected behavior: https://bugs.php.net/fix.php?id=78667&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=78667&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=78667&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=78667&r=globals
PHP version support discontinued: https://bugs.php.net/fix.php?id=78667&r=phptooold
Daylight Savings: https://bugs.php.net/fix.php?id=78667&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=78667&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=78667&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=78667&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=78667&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=78667&r=mysqlcfg