3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php /*{ "_id" : ObjectId("595baefce2810a6a8a94fe2d"), "user" : "1234abc", "type" : "session-started", "name" : "moja o sesja", "reference_id" : "hippo-123", "created_on" : ISODate("2017-01-01T01:01:01.123Z") }*/ class A { private static $_id = 0x10a6a8a94fe2d; private $user; private $type; private $reference_id; private $created_on; public function __construct($user, $type, $reference_id, $created_on) { $this->user = $user; $this->type = $type; $this->reference_id = $reference_id; $this->created_on = $created_on; } public function __toString() { return sprintf('{ "_id": ObjectId("595baefce28%x"), "user": "%s", "type": "%s", "name": "my %s", "reference_id": "hippo-%s", "created_on": ISODate("%s.000Z") }', ++self::$_id, $this->user, $this->type, $this->type, $this->reference_id, $this->created_on ); } } echo new A('u1', 'session_started', 11, '2017-01-01T01:01:01');
based on jjf70
Output for 5.6.0 - 5.6.30, hhvm-3.15.4, 7.0.0 - 7.3.1
{ "_id": ObjectId("595baefce2810a6a8a94fe2e"), "user": "u1", "type": "session_started", "name": "my session_started", "reference_id": "hippo-11", "created_on": ISODate("2017-01-01T01:01:01.000Z") }