Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97671 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 52420 invoked from network); 11 Jan 2017 08:06:30 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 11 Jan 2017 08:06:30 -0000 Authentication-Results: pb1.pair.com header.from=jani.ollikainen@valve.fi; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=jani.ollikainen@valve.fi; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain valve.fi designates 104.47.1.79 as permitted sender) X-PHP-List-Original-Sender: jani.ollikainen@valve.fi X-Host-Fingerprint: 104.47.1.79 mail-ve1eur01on0079.outbound.protection.outlook.com Received: from [104.47.1.79] ([104.47.1.79:15712] helo=EUR01-VE1-obe.outbound.protection.outlook.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 73/BA-55699-387E5785 for ; Wed, 11 Jan 2017 03:06:28 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=valvegroup.onmicrosoft.com; s=selector1-valve-fi; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=5kaW8euc8eddDjvD3eHXK1w/7KUY8ng6kJ36qxo9J/4=; b=4JqNyNbCjowDLtVSK5kuTxklOyYIjOWXwPbd5wzZPjfdl+QTxEf+qWuXFcu+fw7XZzVJvhHHpBMCOvY3zGXOs6s80/MM9YlPKPd8vfv7d0DnYFjBP9Zv1II0Gcm/V+gLzQoxSk7LsY/uDBECBpGPgjW6hzb5JxYJgxQOissmWwY= Received: from DB5PR0101MB1736.eurprd01.prod.exchangelabs.com (10.166.9.135) by DB5PR0101MB1736.eurprd01.prod.exchangelabs.com (10.166.9.135) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.817.10; Wed, 11 Jan 2017 08:06:23 +0000 Received: from DB5PR0101MB1736.eurprd01.prod.exchangelabs.com ([10.166.9.135]) by DB5PR0101MB1736.eurprd01.prod.exchangelabs.com ([10.166.9.135]) with mapi id 15.01.0817.020; Wed, 11 Jan 2017 08:06:23 +0000 To: "internals@lists.php.net" Thread-Topic: Exposing jsonSerialize's depth Thread-Index: AdJr3wCKd9NCtniTR+e4Syl9oAheTA== Date: Wed, 11 Jan 2017 08:06:23 +0000 Message-ID: Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: authentication-results: spf=none (sender IP is ) smtp.mailfrom=jani.ollikainen@valve.fi; x-originating-ip: [2001:14b8:1ec:0:c4ed:aa19:7ee2:a94e] x-ms-office365-filtering-correlation-id: cb941b08-e149-47d4-31c5-08d439f8bc38 x-microsoft-antispam: UriScan:;BCL:0;PCL:0;RULEID:(22001);SRVR:DB5PR0101MB1736; x-microsoft-exchange-diagnostics: 1;DB5PR0101MB1736;7:YO85VJ6l51V2haxvdSV+rq43rK/k4lr4MSIwJkHuP01rutzevAehQ2hhvT6ejAgTAO1evHMtslWI+JGBBaSrvKyhcPSMFGCMBe+8uuryB78bGfA3hgvQOJhlq13awl7N2EFH9zsH8+Q307Ocs5WeMT6VnSCwUgRZ5NlKMs/M9vJd2gAuU935oF1c7UQJKs+SqQeBldgJLI51xqPXS2vgVylWUkHbAJPrSzePFKhVdAhDeCkN7HvgOw+q0AmGewI+fNwU/5OhwkNLVbkbzyjrkfZkXdzqZUoHt3deM7EtBUVmF4Bk7XqkPA2Ov1/OhFOvXOGx/awraNaBggbM9Qf99Lg9LEf3gEDaGq3oq6d/yhxEaPJe5hiqINVOmdMognEwRN7vtrlb4jU9aGoh0lMP9jCmr1oKOd1Bfa5lINZ9M8mxBQ/dpDV+DvH/Pc+ltQ3WsmGuUTCCBnzxhrmtZkUrgg== x-microsoft-antispam-prvs: x-exchange-antispam-report-test: UriScan:(166708455590820); x-exchange-antispam-report-cfa-test: BCL:0;PCL:0;RULEID:(6040375)(601004)(2401047)(5005006)(8121501046)(3002001)(10201501046)(6041248)(20161123562025)(20161123555025)(20161123564025)(20161123560025)(2016111802025)(6072148)(6043046);SRVR:DB5PR0101MB1736;BCL:0;PCL:0;RULEID:;SRVR:DB5PR0101MB1736; x-forefront-prvs: 01842C458A x-forefront-antispam-report: SFV:NSPM;SFS:(10009020)(6009001)(7916002)(39850400002)(39840400002)(39410400002)(39450400003)(199003)(189002)(3280700002)(6916009)(54356999)(110136003)(7696004)(50986999)(122556002)(102836003)(9686003)(92566002)(81156014)(106356001)(1730700003)(81166006)(5660300001)(2501003)(3660700001)(68736007)(2351001)(101416001)(2906002)(8676002)(105586002)(7736002)(6116002)(3480700004)(38730400001)(77096006)(6506006)(8936002)(33656002)(6306002)(2900100001)(189998001)(74482002)(107886002)(25786008)(97736004)(6436002)(305945005)(86362001)(16799955002)(74316002)(99286003)(55016002)(450100001)(5640700003);DIR:OUT;SFP:1101;SCL:1;SRVR:DB5PR0101MB1736;H:DB5PR0101MB1736.eurprd01.prod.exchangelabs.com;FPR:;SPF:None;PTR:InfoNoRecords;A:1;MX:1;LANG:en; received-spf: None (protection.outlook.com: valve.fi does not designate permitted sender hosts) spamdiagnosticoutput: 1:99 spamdiagnosticmetadata: NSPM Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: valve.fi X-MS-Exchange-CrossTenant-originalarrivaltime: 11 Jan 2017 08:06:23.7043 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: ea0c456e-fe7f-4e16-896f-4f5aaeb9c362 X-MS-Exchange-Transport-CrossTenantHeadersStamped: DB5PR0101MB1736 Subject: Exposing jsonSerialize's depth From: jani.ollikainen@valve.fi (Jani Ollikainen) Hi, I've made a pull request where I was asked to start internal discussion abo= ut it.. The pull request can be found: https://github.com/php/php-src/pull/1884 Which relates to request I've also made: https://bugs.php.net/bug.php?id=3D72073 For short the thing is: "We have objects that do dynamic loading and there might be recursions. We = could use recursion depth to decide when we want to do dynamic loading and = when not. Now there doesn't seem to be any way to know how deep is the json_encode pr= ocess going. If we try to use some level in jsonSerialize it just calls one= of those, no recursion there. This could be easily archived by exposing the internal encoder_depth to jso= nSerialize." As I don't know any other way to get the depth info from jsonSerialize, as = it isn't called recursively in PHP side, so adding some static class variab= le and incrementing/decrementing it in jsonSerialize will just not work. Then to why would someone really need that? Well, we have models that uses = MongoDB as a database (created from MongoDB objects) and the models can hav= e references to other models (coming from MongoDB objects). That loading wi= ll happen dynamically and there might be recursions, but we want still to serialize them as we really don't need to go that deep even if the= re is a recursion. This way we can control the depth we are loading new obj= ects and can avoid recursion happening in jsonSerialize and can get the data we need= serialized.=20 If you are thinking why don't you just use the depth option of json_encode,= well unfortunately it doesn't help. It seems to go too deep and get recurs= ion errors and would just later limit the depth it's going as my example wi= ll show if you try if you run it without patched json. Any comments/ideas? --=20 Jani Ollikainen