Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112924 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 26268 invoked from network); 18 Jan 2021 21:32:32 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 18 Jan 2021 21:32:32 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 97B3C1804DC for ; Mon, 18 Jan 2021 13:12:03 -0800 (PST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=BAYES_40,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_PASS, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from NAM12-DM6-obe.outbound.protection.outlook.com (mail-dm6nam12olkn2012.outbound.protection.outlook.com [40.92.22.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 18 Jan 2021 13:12:02 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=QioDk6/FzrF1mu/Oj6gzZ7gEt7paFkhHkO2GFqIRAraYCZ4ruy8cuSZUYTj3UEI4a6kkHw8RMVa5qn3DV5DyefJqQTgA9O6f3dVYt7qraRcvepv0FiPEZPU1NKfrCyzkdOyKDmxybU3KRSRcpe+Lzsj/h6y7P/Bx9sCKoG+0HmH+8yCzEXiR8x+eCfDTUuqBdoOc0OJzPJV/gFVs1JhZTulEYhr4sItohd59YqrtrzLvcWdwhsQXRPiRZ5LKMu71TB7dLk4BR+SV+HmS7xwZrfkLVBfvDgre6seGseJ9pt87gr9hl6DI8OxevKO6uK3EkydDHt6YX0yGXW5XEZSzDg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VJLiCuMY61lrMMI4b2P+UvkmyGyaj6rAcfukNhwpMEA=; b=WvTbP+ONLZvZD8Nr+Hlm7l1GsA7GXkPzvFbCjgaOnaqV3CjE3L6EOHj+D2cQgYGs4bVaezAiLwPJOKhvMo9g0gMMVFW295sU0aAPpT//UNajrRdZGdZCONk3kusjgiFWCI52edQ7D0vGBVLpxJq663Sl8cDk3B5drjT9/uRqobFZ9YfV/pnlramnG1Z15UTiVn0PvMD8+wtdx/qidOnyy8eBmVmhvlBG41pIKjlda1E74/nr5931CRX0E9pFSwv52qi1TG2GKDGZaUyz8jRkIyCIROgWsMyKc3/FJBzHDfCVvp5VYzAOsDBLAMw91YZeZvpxP5YuU3EeNtfh8zegxg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=none; dmarc=none; dkim=none; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=hotmail.com; s=selector1; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=VJLiCuMY61lrMMI4b2P+UvkmyGyaj6rAcfukNhwpMEA=; b=cGdJY7NPEoabwrOqZ4cdafOvnAqwCCTtI9LEufuppyP5Td2iV2zVL2fS6Sl22v1tHSiMS6kUIPnaZhoHO0gxWgsghifpfdjcIqxesszz6cIyJlrqh6x9qeaBmPCanKhcmAuKV9CRVcGd7wHf5r/JLQJ795gsgiYfE+DVrGGvGPHczMpmjQonn77g2SORHeXUnBWho/xwzDVsSfye2kLrBcc6Ffyt+Zt5EigMLsbxUgLJrtdJfTEyZr2qurd8hh4u3aX93d4r4k4AXklXROQCantlcUfSKfypOrAppFmHCAS5VvhRRutxtYvvSqrMbYu2NqfQcIvCu3iphP38osoFnw== Received: from BN8NAM12FT048.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc66::52) by BN8NAM12HT025.eop-nam12.prod.protection.outlook.com (2a01:111:e400:fc66::269) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.7; Mon, 18 Jan 2021 21:12:01 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc66::41) by BN8NAM12FT048.mail.protection.outlook.com (2a01:111:e400:fc66::214) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.7 via Frontend Transport; Mon, 18 Jan 2021 21:12:01 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::b4c4:dc11:5337:821d]) by DM6PR07MB6618.namprd07.prod.outlook.com ([fe80::b4c4:dc11:5337:821d%4]) with mapi id 15.20.3763.014; Mon, 18 Jan 2021 21:12:01 +0000 To: "internals@lists.php.net" Thread-Topic: Proposal: short_var_export($value, bool $return=false, int $flags=0) Thread-Index: AQHW7dmyhWuNOI20o0CCrwAKBqqvfg== Date: Mon, 18 Jan 2021 21:12:01 +0000 Message-ID: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:5E4A19ED8C86210429A50A48BF508109CCCE719C147D836EAC5C2050BEF7F088;UpperCasedChecksum:A2D422F52FDE00FF597D0993B1DEE64114CF873103CE2D8ADB5ADEBD425B89BC;SizeAsReceived:6853;Count:41 x-tmn: [fNLhEveOlGML3RlHlIRWWuvPPLGENzZQq5usE91m2zSAo4gFrnDuKO1yFManx7tP] x-ms-publictraffictype: Email x-incomingheadercount: 41 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 0b9cd0d5-3314-4fa9-e696-08d8bbf5b2f0 x-ms-traffictypediagnostic: BN8NAM12HT025: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: QCWaZ1n7p/zvvz6cVdD1+kUIPRawl1oyNSMLjDuWsDXnIhwvEMZIdukUgbKbrWVhfrwe+HsYnXiRx535mV6IuqdU2WV9XNGjhiFTV5SPi8wVnhYR3qkp7N0+FGCKCGU4N1DSH2wNXmWcALtSS59oqkb2MNsgLdwzT4P9DkSELyWCcDNu/bCgy3skjwpo5FmW9m9lQLbJA7QqSt17jqf7vPMfgmgf9Pa3hfM0Z+gFe6zgbRN3hz3PZOZLlbP4O+jqdewzRqy2BrU6H3m4/kdBjvzrfNcbaCxl5kERiZNOB84= x-ms-exchange-antispam-messagedata: M5eBw5ynJrfpnVKqJ0Zmitw8m7r1O/zXKSTKRcH1/hNDeERK/+VBF3iHMR7q5h62bC3OdQzmiiYIpTyaNwtt6jekpKFHipZdaYATEWwKl63uVecMqJeaQ+Qy0MARNmGlhu1QNqc6DCS3ttUwxvEYxBNEuMIAk0jNdbpM0xpsJJMYiYCGMbyrG21OJQ6sEGAmrGMHPvTZWZ3OWiazUHQa/A== x-ms-exchange-transport-forked: True Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-AuthSource: BN8NAM12FT048.eop-nam12.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 0b9cd0d5-3314-4fa9-e696-08d8bbf5b2f0 X-MS-Exchange-CrossTenant-originalarrivaltime: 18 Jan 2021 21:12:01.5999 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Internet X-MS-Exchange-CrossTenant-id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-rms-persistedconsumerorg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: BN8NAM12HT025 Subject: Proposal: short_var_export($value, bool $return=false, int $flags=0) From: tysonandre775@hotmail.com (tyson andre) Hi=A0internals,=0A= =0A= I've created a PR https://github.com/php/php-src/pull/6619 to add an altern= ative to var_export().=0A= The proposed short_var_export() also outputs/returns a parseable representa= tion of a variable,=0A= but adds requested features for var_export.=0A= =0A= 1. Use `null` instead of `NULL` - the former is recommended by more coding= =0A= guidelines (https://www.php-fig.org/psr/psr-2/).=0A= 2. Change the way indentation is done for arrays/objects.=0A= See ext/standard/tests/general_functions/short_var_export1.phpt=0A= (e.g. always indent with 2 spaces, never 3 in objects, and put the array= start on the=0A= same line as the key)=0A= 3. Render lists as `"[\n 'item1',\n]"` rather than `"array(\n 0 =3D> 'ite= m1',\n)"`=0A= 4. Prepend `\` to class names so that generated code snippets can be used i= n=0A= namespaces (e.g. with eval()) without any issues.=0A= 5. Support opt-in `SHORT_VAR_EXPORT_SINGLE_LINE` in `int $flags`.=0A= This will use a single-line representation for arrays/objects, though=0A= strings with embedded newlines will still cause newlines in the output.= =0A= (`"['item']"`)=0A= =0A= Changing var_export() itself has been proposed 9 months ago (https://extern= als.io/message/109415) =0A= but the RFC discussion seems to be on hold.=0A= https://externals.io/message/106674#106684 suggested adding a new function = as an alternative.=0A= One of the major objections is that changing var_export() (instead of addin= g a new function) would have these drawbacks:=0A= =0A= 1. It would be impractical to backport/polyfill calls with 3 args to older = php versions, if `int $flags` was added.=0A= ArgumentCountErrors are thrown in php 8.0 for too many parameters, and e= arlier php versions warn=0A= 2. If defaults were changed, then thousands of unit tests in php-src and ot= her projects may fail due to=0A= tests expecting the exact representation of a variable, requiring a lot = of work to update tests=0A= =0A= I feel like the user-friendliness of the enhancements makes adding another = function=0A= to PHP worth it. (e.g. copying short_var_export() into a code snippet such = as the expectation for a unit test or a configuration)=0A= I don't believe I've seen an RFC for a separate function before.=0A= =0A= Also, a native C implementation would be much more efficient than a polyfil= l implemented in PHP,=0A= e.g. https://github.com/brick/varexporter/issues/14=0A= =0A= I plan to start an RFC document shortly. Thoughts?=0A= (e.g. for the name, short_var_export() seemed more appropriate than var_exp= ort_short(), pretty_var_export() or canonical_var_export())=0A= =0A= Thanks,=0A= - Tyson=