Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112927 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 93258 invoked from network); 19 Jan 2021 15:32:41 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Jan 2021 15:32:41 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CA7491804D3 for ; Tue, 19 Jan 2021 07:12:25 -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.5 required=5.0 tests=BAYES_05,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 NAM11-BN8-obe.outbound.protection.outlook.com (mail-bn8nam11olkn2077.outbound.protection.outlook.com [40.92.20.77]) (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 ; Tue, 19 Jan 2021 07:12:24 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=gd8Ks+qJZf245nuI7AoipLaXvzp31wBAVq5sqI/jesJ+4Br7/RIUIVJvo2/qp/LwTbdyN7jcSOxJRw7Cf/OSfvTJRIo9r1bEHXC7X8e330PPHmiKkm0NR7tYibQYaGVou4yb1xCAgjsaquFxP6xcRyVPubE7zHi96Fs9WevVWUAnMne70C4wo7sn021SVnso/0vdYrUddydukOAAeb6wI8/6WRRkq8G7Ub24MPbME+MXempGbb/p6nPzBTBw0a6MTJZ1kBRvsLSRp6mA3cBgS8KUDjPH8v0WDFG2+efwCqZjD/Usr2RHuKvhzJUeC5yOLVFNzSHonY6Dm0QBCQhmJg== 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=q9MbIdqXWjWz1r2rDGvngwsaJEsbnTJCcGZtI6SThGk=; b=aVVBXao+3iGMi6E3UQTFnv4/1uI6RxRe2lB7qC0Tz3lx7iuP3qVDwbTj9omqboxcn0No+2YSFd8aTY4hz6Nd1QNbw6SIALhkH7tbFaoP60GHu0YPxU9IvyABjRHFoHBoSux7YWIWsi9BzQ3VWcRy3PJQdIGZl0C01BAcn4z05ocixpObmjkR3IPueXicVDu3xmwC2HyEBkF/ZBnLaRTm08Xkoa5VfFuSRDZBxepH1HMjwo/elKwpnyvXU93hjTB7TWZHrDHc6CEeu+X/OqbYh03VBoZu+DY90GlzJPqgSweeO9AdPrqpsGpFC8wBtv8n6JdVNhsSIBXXP3uEv/vdtg== 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=q9MbIdqXWjWz1r2rDGvngwsaJEsbnTJCcGZtI6SThGk=; b=u+8Cps90MU23ptVZCErCdPR8oYmPA0Q0NwurUF5dYO5Pr36eHZW4dlVEX/NoGnecgpTZdRvXqUiAMriQXZsz5ycH49xoC/BmxijmRC0zuCstvQZFsDWrsx2UK+48mWZDM7QhCvSsEF7NYdJ5Dby5pO/z/z7azYEi52uh0jRV9uiP6ahvLm7uMQOiM+qgDnoponM/UF0Q3GaWoO2R/ZLBIEH47e2WxWWSO3jwAWmxcOfeXUYLJCDonVPGZDKRQYJz+5b78PoVyUhSnwN6oVyJUMf1wf36f5Q7N/hDn1/0r0+6oyGiW/hEwu6+1i1EXFx7tcwknKA0SpH/irQFMtuWZw== Received: from DM6NAM11FT014.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4d::42) by DM6NAM11HT125.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4d::404) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.12; Tue, 19 Jan 2021 15:12:23 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc4d::4a) by DM6NAM11FT014.mail.protection.outlook.com (2a01:111:e400:fc4d::388) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3763.12 via Frontend Transport; Tue, 19 Jan 2021 15:12:23 +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; Tue, 19 Jan 2021 15:12:23 +0000 To: Nikita Popov CC: "internals@lists.php.net" Thread-Topic: [PHP-DEV] Proposal: short_var_export($value, bool $return=false, int $flags=0) Thread-Index: AQHW7dmyhWuNOI20o0CCrwAKBqqvfqout8uAgABVQ1Q= Date: Tue, 19 Jan 2021 15:12:23 +0000 Message-ID: References: , In-Reply-To: Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:1CD4A8EAE3709176C5E3700B1F6D24ED9297CB4A6823AFE88481C0E5A7D67F82;UpperCasedChecksum:21847ED1DFCB36B71A60A1C2216E08869A7949F354ED55F670CDE908B17F4530;SizeAsReceived:7229;Count:45 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [q+ic1gDKH8eeFH25CH3Swu8hdjWDLM2ikvh4wywlP3EIm3j438Bv4oSmQSTj3unC] x-ms-publictraffictype: Email x-incomingheadercount: 45 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 59190824-41b6-4d71-90d8-08d8bc8c9fea x-ms-traffictypediagnostic: DM6NAM11HT125: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: My1jLTyrVhDbj1hIfRshzUcPEx2WV3hzCOM2svvKRW1i73s75WqVkJE77MPzkEnbujbc662Qvpmm/bSO2auDY4wSqubdj2FfYYh1/72dtPTVNX0a5p2GSta5JOL/mjz80zuRgslP8MeRs/uTRLsnk5Jcpe+EmQJy7nkjqPh1IXMKguZpsWF3Q3oeG3lchgKrpIE1EV45Oi00/beYcj6HLFKlu6G55jLO7DwGva72s4xI5T8r06J0ql35W20VOh+y x-ms-exchange-antispam-messagedata: MeHlyBEo1zoTsoRXcxbulGhuIbIX4vGVVRnqiQD6lGdHnQmDFiywkJjq2D43vcCBRjpVl8M1LWl0AioFTVCR1aaxiZ9hJCrmJXAN9D43KYcbDxCT1P7Nvfn62LW3yfQddYpXYHgiG6cUwNVAFWjTOpKpoWTItqs5DCHohsOGV87hvCg+ZnEIrfUX5eFH3RLljr9oesosqc63YwQpRzJaEg== 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: DM6NAM11FT014.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 59190824-41b6-4d71-90d8-08d8bc8c9fea X-MS-Exchange-CrossTenant-originalarrivaltime: 19 Jan 2021 15:12:23.6368 (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: DM6NAM11HT125 Subject: Re: [PHP-DEV] Proposal: short_var_export($value, bool $return=false, int $flags=0) From: tysonandre775@hotmail.com (tyson andre) Hi=A0Nikita,=0A= =0A= > The formatting of var_export is certainly a recurring complaint, and prev= ious discussions were not particularly open to changing current var_export = behavior, so adding a new function seems to be the way to address the issue= (the alternative would be to add a flag to var_export).=0A= > =0A= > I like the idea of the "one line" flag. Actually, this is the main part I= 'm interested in :) With the one line flag, this produces the ideal formatt= ing for PHPT tests that want to print something like "$v1 + $v2 =3D $v3". N= one of our current dumping functions are suitable for this purpose (json_en= code comes closest, but has edge cases like lack of NAN support.)=0A= > =0A= > Some note:=0A= >=A0* You should drop the $return parameter and make it always return. As t= his is primarily an export and not a dumping function, printing to stdout d= oesn't make sense to me.=0A= =0A= It seems inconsistent and prone to bugs when refactoring (e.g. converting t= o string and not using the result)=0A= to have two functions named var_export where one prints by default and the = other doesn't, but otherwise .=0A= Changing to a different name entirely would solve that, such as var_repr(),= var_representation(), serialize_[value_]as_php_snippet(), etc.=0A= =0A= >=A0* For strings, have you considered printing them as double-quoted and e= scaping more characters? This would avoid newlines in oneline mode. And wou= ld allow you to escape more control characters. I also find the current '' = . "\0" . '' format for encoding null bytes quite awkward.=0A= =0A= I'd considered that but wasn't sure if anyone else would want that - I also= found it annoying for `\0` and `\n`, as well as other control characters (= 0x00-0x1f, e.g. `\r\t`)=0A= =0A= >=A0* I don't like the short_var_export() name. Is "short" really the prima= ry characteristic of this function? Both var_export_pretty and var_export_c= anonical seem better to me, though I can't say they're great either. I will= refrain from proposing real_var_export() ... oops :P=0A= =0A= Potentially not shorter with the extra backslash and the potential for swit= ching to "\$var\0\ntest\\" for string encoding.=0A= =0A= var_representation($var, int $flags=3D0) seems clearer=0A= =0A= Thanks,=0A= Tyson=