Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112970 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 92765 invoked from network); 23 Jan 2021 21:27:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 23 Jan 2021 21:27:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 005C71804C6 for ; Sat, 23 Jan 2021 13:08:01 -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_20,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 NAM10-MW2-obe.outbound.protection.outlook.com (mail-mw2nam10olkn2079.outbound.protection.outlook.com [40.92.42.79]) (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 ; Sat, 23 Jan 2021 13:08:01 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=A3H4E9mOT5HOnSIHbh2B0OTwfvVJZQmcqA8Jwi8auwLseJRxpeJu17Zq9DO5gOERQihJIXXZcQpTTvl7ywHkmQlQ+CEsAdCg6LEbXnhOL/PiEZJE8Y+qyhHt3zkk0UEKd3kRm8j+5tv/o8JSNNehqi819eXiV6AOk7Jo6HOtH0CethkVMHuuwgCXB+T/pCgZFSCe90NPsno8knY/ykllndNK/9QW9o6lrmpiFHfLGnF0/VO/RtyMH6d951SUdIMowAlsMyISzs41so/qKxTSmb5Dm5sQNZvIK6MCu3BMznXrp39K58euesZXug2egd9AD2gPDgUqhO2iwaztsk8gtg== 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=88QOW0YLucOPHn6hCvzW0lBHokOFpRB/XpJxbZ13Axw=; b=WHAmgXx3+oxJgdag/UHlXGcF+ugv1qc85JOoMLUGwx91LMvGUXxibetMAcVDEUrPI7q8iejyyrkwXRLkiZZt8LC68h5JRmgE63Pin+zHM6vlMje0/750gca5F/PJpCwPL0ncPK9dIDHXvAhYDOLjIU1oNFYlTMWTSEnMYhLvkjJ8VrAPSTnye/NvLCP2xDDUF5TsfGulHKylun0QdlTyW6v4R4Nk1LqY/JpO4OV/nYFYc+hT8AezdJ5Q+LC4JPOfQbuYYJsO3QJQ7XqywsnnSKPhMOdoWJ0MxMdSzs1Z0lsMlwV9eWEKaFuMKmvj4VmC5Y62AZOjRp2u35DTN3hqyQ== 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=88QOW0YLucOPHn6hCvzW0lBHokOFpRB/XpJxbZ13Axw=; b=XU6rTOwzEgDSeuHXHj+nlP3qY4VESS5JVxWrqQpiJBARVzsl5YK/0VQCjS0sftfe+hFescqi92vqHRCqkIupwUL7dB8YdGFO1sjGMtfL0i0/f7olIplILeC/uzYsWVSzxX8HMInbaGdy/OvaxVeEnZwwclGV0kOQBTvf0S2BTp/LzpaOBk/LR/C+QUV4P5J+iLOCeJVyXRDNRTfZirIy5dX2RsBgxwjH0jypb+WGw606aLopHk1DSTKgjBOObS/NCxzkmM62Ixh7b4/wjtJyF+lwDClXOeLddKT8AU8JhrWfymtvgM+l9aHbBKUMAf7U8gcZQ91wt28vTygbzcbL7Q== Received: from MW2NAM10FT060.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e87::51) by MW2NAM10HT029.eop-nam10.prod.protection.outlook.com (2a01:111:e400:7e87::230) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11; Sat, 23 Jan 2021 21:07:59 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:7e87::4a) by MW2NAM10FT060.mail.protection.outlook.com (2a01:111:e400:7e87::363) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Sat, 23 Jan 2021 21:07:59 +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.3784.017; Sat, 23 Jan 2021 21:07:59 +0000 To: Rowan Tommins , "internals@lists.php.net" Thread-Topic: [PHP-DEV] [RFC] var_representation() : readable alternative to var_export() Thread-Index: AQHW8R1wWWGP+37l0kiexDpDbUAmVKo1egmAgAAyURI= Date: Sat, 23 Jan 2021 21:07:58 +0000 Message-ID: References: ,<5ae166a8-378e-b3bc-056a-8ccf4f3a1ddd@gmail.com> In-Reply-To: <5ae166a8-378e-b3bc-056a-8ccf4f3a1ddd@gmail.com> Accept-Language: en-CA, en-US Content-Language: en-CA X-MS-Has-Attach: X-MS-TNEF-Correlator: x-incomingtopheadermarker: OriginalChecksum:3D12C0C29076D1FA3EDA29069FED30F4847758AF13B16353EE37121A427F9334;UpperCasedChecksum:9E8964C7CAAADE2CF8C4E1E26BE4EE416A4C64046B2AECEA160A2ED9FFCE9CB0;SizeAsReceived:7191;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [jKx0rW/GYKmn6ETrqweLPfTfcPbW5QBMW3TyXHWjzXIZXXYjO2lGLwFKDyKLBG/J] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: a0aec3bb-465c-4241-a5ef-08d8bfe2f683 x-ms-traffictypediagnostic: MW2NAM10HT029: x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: QBDWJk8BTOWne122NK4Ti7GziZlmV3nClfVYsXJxdqSfis56kVwz16Dx8Sd3PBXGjZ+D4GjacDjVopv2fKfPScBOio+p0JOjlTi3HpPjeA/9pNruZpkPkYCQd9pDrWggc76ZulDdrEjZCfkRsINyDSODqbIraHylCtthE00wZCnG+UQfsx1nd9SnsW7Y9CjSxlOEbo5c8wWeX53qBzWtVWXDn1jTjF9u6ZmjcB7erldmw/cPGkJyqR6BVfFq8SZdAzaLLSBUiJk+1ydwvVoPc4kFd5p93Wp4fmRA2VuVCWI= x-ms-exchange-antispam-messagedata: q+Tpl+Eh1MemASpIJbSEdiRHKjK1CMQQu5qKVzxN1p7JDRpTn/YRZmvf5OdkwzzekjspiUMjrZ10GmjhEFnLryX7pSGg5WKeMNqSxIAwsSrqqGRBDyJVDrfS6ADFoFtKk6QKARnztmXeJD2kCvbzk4/xuEU0V5ujc/q+/do7gHM54a6bf4ohxg3AvQK5y6rt368llde0p7uWqK+Mca5rlA== 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: MW2NAM10FT060.eop-nam10.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: a0aec3bb-465c-4241-a5ef-08d8bfe2f683 X-MS-Exchange-CrossTenant-originalarrivaltime: 23 Jan 2021 21:07:58.8194 (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: MW2NAM10HT029 Subject: Re: [PHP-DEV] [RFC] var_representation() : readable alternative to var_export() From: tysonandre775@hotmail.com (tyson andre) Hi Rowan Tommins,=0A= =0A= > > Hi internals,=0A= > >=0A= > > I've created=A0https://wiki.php.net/rfc/readable_var_representation=A0b= ased on=0A= > > my original proposal in https://externals.io/message/112924=0A= > >=0A= > > This RFC proposes adding a new function `var_representation(mixed $valu= e, int $flags=3D0): string`=0A= >=0A= > My hesitation remains that this is just duplicating existing =0A= > functionality with only cosmetic differences.=0A= > =0A= > As a user of PHP 8.1, how would I decide whether to use print_r, =0A= > var_dump, var_export, or var_representation?=0A= > =0A= > And under what circumstances would I bother to write =0A= > "var_representation($var, VAR_REPRESENTATION_SINGLE_LINE);"?=0A= =0A= You have a good point on needing to document the circumstances where this w= ould be useful.=0A= I meant to write up the reasons where an end user would=0A= or wouldn't want this functionality - it's useful when reviewing or voting = on the RFC.=0A= I've added those to https://wiki.php.net/rfc/readable_var_representation#wh= en_would_a_user_use_var_representation=0A= , including when I think the VAR_REPRESENTATION_SINGLE_LINE flag would be u= seful to users.=0A= =0A= var_representation may be useful to a user when any of the following apply= :=0A= =0A= - You are generating a snippet of code to eval() in a situation where the s= nippet will occasionally or frequently be read by a human (If the output n= ever needs to be read by a human, `return unserialize(' . var_export(serial= ize($data), true) . ');` can be used)=0A= - The output is occasionally or frequently read by humans (e.g. CLI or web = app output, a REPL, unit test output, etc.).=0A= - The output contains control characters such as newlines, tabs, `\r` or `\= x00` and may be viewed or edited by other users in a text editor/IDE. Many = IDEs may convert from windows line endings (`\r\n`) to unix line endings(`\= n`) automatically.=0A= - You want to unambiguously see control characters in the raw output regard= less of how likely they are (e.g. dumping php ini settings, debugging myste= rious test failures, etc)=0A= - You are writing unit tests for applications supporting PHP 8.1+ (or a var= _representation polyfill) that test the exact string representation of the = output (e.g. phpt tests of php-src and PECL extensions) =0A= - You need to copy the output into a codebase that's following a modern cod= ing style guideline such as modern coding guidelines such as PSR-2. It also= saves time if you don't have to remove array keys of lists and convert arr= ay() to [].=0A= =0A= (I added that and a section on when/why a user may decide to use VAR_REPRES= ENTATION_SINGLE_LINE in the RFC)=0A= =0A= As for print_r() - https://www.php.net/print_r seems underdocumented - It d= oesn't mention how booleans, null, and floats are represented (same as prin= t()) except in user notes.=0A= =0A= The online documentation for var_export/var_dump explains what they do but = not why/when they would be used,=0A= it may be worthwhile to submit a PR to expand on those.=0A= =0A= Regards,=0A= Tyson=0A=