Closed
Description
Awesome work on this extension!
It would great if calling JSON.stringify()
on a PHP object would make use of that object's jsonSerialize
method if the object implements JsonSerializable
. That is, the JSON.stringify()
result would be easily controlled by the PHP author and have the same outcome as json_encode()
.
<?php
class Foo implements JsonSerializable {
public $bar = 'bar';
public function jsonSerialize()
{
return ['bar' => $this->bar];
}
}
$v8 = new V8Js();
$v8->foo = new Foo;
$v8->executeString('
print( JSON.stringify(PHP.foo) );
');
Given the above code the current result is:
{"$bar":"bar"}
But the desired result is:
{"bar":"bar"}