Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113052 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 33352 invoked from network); 2 Feb 2021 19:21:38 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 2 Feb 2021 19:21:38 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 6BC571804DD for ; Tue, 2 Feb 2021 11:04:55 -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=-2.6 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_ENVFROM_END_DIGIT, FREEMAIL_FROM,RCVD_IN_DNSWL_LOW,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 EUR02-HE1-obe.outbound.protection.outlook.com (mail-oln040092068091.outbound.protection.outlook.com [40.92.68.91]) (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, 2 Feb 2021 11:04:54 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=IvwuD7SwfrO2WmNeQowtwl3exe3/f5z7fOd8OTzJhy/K1Tjc8mtlPhK2LKl4zLR1cFeHNybDs4tpWKgUhmK+Enw0z7+LrK0l3rgaF5q80q43BiLsGwtDMMbS+z84zj8MWUu8FndLtPMz4yikyg0441UEFPpXZ5LMRhSlFyCvDltqw95kvDZLh81d5hNj+qqRAH5fxHsioa4yHCIQtDik0s7lmNuXX49CL995M6en9PhXNZgWK32Or0by0LvgZTt7Lh5oJmS+//SiPy3XUW8gdiYwG/T8JrGmA7BBUJLKSfubGyhsnYlHfNeOkr1Kv4scGs+TBYZ+tWLQxAkDV9kHgQ== 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=n9sGj+RFcGJBL6tWY2hKS81iyGKp0eVeIeY8zAQ3js0=; b=cPVofJHmXutlxQJAPcJpg+tbQ4XmWl2Uh9/j+PXcxrHtbkW007ccYxVCMuAd5fHbEyO+638cJC+W41IwOiqWNDu+B94DfCXxHMp3e2a8h8I1VDYcnz7b0SNU4gtLw4VA+q3O5zG6AMPnvN5aP/Mv5/Lk96EsSVa4fzRcgsF5NozTdQCE3QqSBWSr7aCH6zJbqdO2TATy71lysHXapcu0ynPwa0RRbu0+BsErmklqyJT5+fS4m6e2mL1EV4nF2tZtoFsFatxlkoTrWmYh7P3rwsm5v0NntBF7GXZNE1nEX5c1rt1uoGVtADJZujj3fSThtenlxAGEfsqnPYVaf2CwXg== 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=n9sGj+RFcGJBL6tWY2hKS81iyGKp0eVeIeY8zAQ3js0=; b=bHcQbpzFkfaIuqA1tOjYLsaMe3dcXXGRpWS+9o23vQhXT54VXxo1ktW0X2hwGHLH+y106DI8xSHVqHx2+mHSVpELlsB+gwmd1JQjFdTNZHd8rAR48UgUkM64eHNeqtSbaeUCMgZvxLKklzXN4Y/vwmPpoGer5O4zf3aQX477RIsN2Nv5pEzDQv/2s643qZTEFJVvEs3XfQpVbAjjrajVOkRkADzOa43H/LXKVA0jtdwE/F1mYflCyt62rMR4n2xRQnSfMgYXS1rwls/sCB+4sRUfHXLiRSWYAfmqXC9yRkEk7tMn+iHelLLn2DWIDH2Tq6mWNvjtRPwwTFVRnRTM4g== Received: from VE1EUR02FT061.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1e::4d) by VE1EUR02HT202.eop-EUR02.prod.protection.outlook.com (2a01:111:e400:7e1e::342) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11; Tue, 2 Feb 2021 19:04:53 +0000 Received: from VI1PR02MB4703.eurprd02.prod.outlook.com (2a01:111:e400:7e1e::49) by VE1EUR02FT061.mail.protection.outlook.com (2a01:111:e400:7e1e::494) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3784.11 via Frontend Transport; Tue, 2 Feb 2021 19:04:52 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:825F2713C190180DCC7EEA46B7A019FED9C10965FC38800A536917AB63F9301D;UpperCasedChecksum:46ABB8F0E55483AC35F08C1D28FEA331BBD65AA848B23D45282480C3C23845CA;SizeAsReceived:8918;Count:46 Received: from VI1PR02MB4703.eurprd02.prod.outlook.com ([fe80::e158:41d3:b378:86e2]) by VI1PR02MB4703.eurprd02.prod.outlook.com ([fe80::e158:41d3:b378:86e2%6]) with mapi id 15.20.3805.019; Tue, 2 Feb 2021 19:04:52 +0000 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Tue, 2 Feb 2021 20:04:50 +0100 References: To: PHP internals In-Reply-To: Message-ID: X-Mailer: Apple Mail (2.3445.104.11) X-TMN: [2AkFotSe+I2Vzwq467F2iVu8zaNdudYCnBGQL8y17PtE4LcGdEDbNICYL0WrWF9P] X-ClientProxiedBy: LO2P265CA0267.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a1::15) To VI1PR02MB4703.eurprd02.prod.outlook.com (2603:10a6:803:8f::13) X-Microsoft-Original-Message-ID: MIME-Version: 1.0 X-MS-Exchange-MessageSentRepresentingType: 1 Received: from [IPv6:2001:7e8:c83a:5400:30f6:13da:890:c3f8] (2001:7e8:c83a:5400:30f6:13da:890:c3f8) by LO2P265CA0267.GBRP265.PROD.OUTLOOK.COM (2603:10a6:600:a1::15) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3825.17 via Frontend Transport; Tue, 2 Feb 2021 19:04:52 +0000 X-MS-PublicTrafficType: Email X-IncomingHeaderCount: 46 X-EOPAttributedMessage: 0 X-MS-Office365-Filtering-Correlation-Id: 5acd34a2-c42a-43c0-43e4-08d8c7ad6bbe X-MS-TrafficTypeDiagnostic: VE1EUR02HT202: X-Microsoft-Antispam: BCL:0; X-Microsoft-Antispam-Message-Info: B9nFUsodqEWv8c3AQBDxzR6gYFLVLa+CmRXlT23bYL5tFhcfV6cSn99FEzJJdDRS/EoYHO4DZSIVV/jJBM2ZgzvfCPv7ny/TXEWtkP0GBItnO+QI3oMIOdcaD7c14a4k6xiD5I4iEVhEOtDAzwGphD8Ta9YkCQREMSRmn5JUT51VjUQhy22fTaMJQ5UFz7z2rfp15F1txBpSLP/OEVij6AtiDmskLQFpl/5Dkk8SFHPveKRDHIGAAQe6VP/hkO5spNcOJepcbdzlz1AY5KntfsWYj3iXTF0Ciyn7t8KFu+ZDuIT/N4sBbaTRSH+6MqLyP73MjFbB9CnmAgPLmh/nmR5jtcY3Uz1t54eGG0SygbPcuc3Ic6bnDaPFg3sEYD0tOl11z6lQUnXaurU10C5eu6Zl5hLjzHEolYMN5wALaOdz3XIp/o3XFHWP79P+T/xd X-MS-Exchange-AntiSpam-MessageData: UXZtFff5WlQdZGhZunrWUbeyW0usL6akHwPgDakVh5drySO7Vj0jopak72RLNiijyoOW531N2JBF1L9n86+i2hFF/VfmQKDiukyWg/mQGGDsU/fSSUR+mml8d2TQF2uzBloXoI2LPYDf2Hc/eWwlL8f3uCk7I+OsAcaCxjrzTURB3wEcDIxNoV5FqQC8+RGUIf/nNcPWfz8jafjL7HDw3A== X-OriginatorOrg: hotmail.com X-MS-Exchange-CrossTenant-Network-Message-Id: 5acd34a2-c42a-43c0-43e4-08d8c7ad6bbe X-MS-Exchange-CrossTenant-OriginalArrivalTime: 02 Feb 2021 19:04:52.8463 (UTC) X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 84df9e7f-e9f6-40af-b435-aaaaaaaaaaaa X-MS-Exchange-CrossTenant-AuthSource: VE1EUR02FT061.eop-EUR02.prod.protection.outlook.com X-MS-Exchange-CrossTenant-AuthAs: Anonymous X-MS-Exchange-CrossTenant-FromEntityHeader: Internet X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-Transport-CrossTenantHeadersStamped: VE1EUR02HT202 Subject: Re: [PHP-DEV] [VOTE] Dump results of expressions in `php -a` From: bobwei9@hotmail.com (Bob Weinand) Hey Tyson, > Am 02.02.2021 um 03:35 schrieb tyson andre : >=20 > Hi Bob Weinand, >=20 >>> Am 20.01.2021 um 01:55 schrieb tyson andre : >>>=20 >>> Hi internals, >>>=20 >>> Voting has started on https://wiki.php.net/rfc/readline_interactive_she= ll_result_function >>> on 2021-01-19, and ends on 2021-02-02. >>>=20 >>> This RFC proposes to dump the results of non-null expressions using var= _dump/var_export() by default in `php -a` (the interactive shell). >>> Additionally, this adds a new function `readline_interactive_shell_resu= lt_function` to the readline PHP module. >>> This function only affects interactive shells - it can optionally be us= ed to set or clear a closure when `extension_loaded('readline') =3D=3D=3D t= rue`, >>> but that closure would only be called in interactive shells (i.e. php -= a). >>> (That closure would be called instead of the native implementation with= the snippet of code that was evaluated and the expression's result, >>> if a php statement contained a single expression such as `2+2;` or `$x = =3D [1,2];` (that could be used as the expression of a return statement) >>> - Dumping of expression results can be disabled using an ini setting or= at runtime=20 >>>=20 >>> Thanks, >>> - Tyson >>=20 >> Hey Tyson, >>=20 >> My main concern in this iteration of the RFC is: what happens with big/d= eeply nested objects? >> They tend to spew tons of lines if var_dump()'ed. Do we have reasonable = depth/output limitations in default dumping mode? >>=20 >> I'm often enough using php -a to do some quick ad-hoc processing (exampl= e, read a big json file, and then access a value; instantiating a mediawiki= bot framework and calling replace on it; ...). >>=20 >> It's really cool to have any interactive feedback at all, but please, at= least by default, limit the output. (An example is the JS REPL in browser = console - it shows you a minimal preview of the object, and then you can ex= pand with your mouse. Obviously with a pure cli application, this needs dif= ferent - intuitive - navigation.) >>=20 >> As it currently stands, this makes php -a unusable in any but the simple= st cases, without just disabling the whole feature. >>=20 >> I like the whole feature, but the missing output limitation (I have yet = enough nightmares from var_dump()'ing the wrong object filling my shell wit= h tons of irrelevant information=E2=80=A6 I don't need that potentially hap= pening on every single evaluated expression) >>=20 >> Thus I'm voting no, for now. >=20 > As-is, the entire object or string would be dumped with var_export/var_du= mp to stdout. >=20 > Thoughts on the adding following output truncation mechanism=20 > (for the default C result dumper implementation) > before printing the results of the returned expression=20 > (the user output continues to be untruncated, and the existence of cli.pa= ger=20 > would not affect this mechanism in case the binary is not actually a page= r)? > For arrays/objects used with var_dump - the equivalent of=20 > `ob_start(); var_dump($result); $result =3D ob_get_clean();`=20 > would have to be used first from C since var_dump still writes to the out= put buffer (php_printf(), etc.) var_dump() tends to be quite intensive in newline usage. I don't think var_= dump() (as is) is the best mechanism to print. At least I'd use one propert= y/one array argument =3D single line instead of two lines. Additionally, when dumping a nested object, it's more valuable to see as mu= ch as possible from the primary object rather than the deep nesting. > I'd omitted output truncation from the RFC because I wasn't sure how many= people=20 > would consider it excessive to include a limit on var_dump output, and th= ere was little feedback before the RFC vote started. Yeah, sorry for the late comment on that :-) > The simplest implementation would be to truncate to a byte limit and appe= nd `...` if truncated,=20 > but the main concern that's been brought up is the approximate number of = lines. > Obviously, there'd be a value in truncating the output if there were to b= e megabytes of output, > though exactly what settings make sense as a default would vary. As mentioned a section earlier, there should be limits according to the nes= ting-level =E2=80=A6 e.g. if it's the top-level value, a string may have 20= lines printed and array and objects as well. And array entries/properties = should then be in a single line or take up to max ... 20 / count(properties= or array entries) lines (width before truncation can be determine from ter= minal width), which then can be mostly in one line flattened output. The general rule here should be, show me my object/array at hand and give m= e a brief overview of what's nested within - and if I'm interested in detai= l, let me (manually) output that object. Also consider, when dumping strings within (nested) arrays/objects to repla= ce newlines with \n, for nicer display. > C would not print anything (e.g. `=3D> `) or even call var_dump/var_expor= t if the limits were set to 0. >=20 > ``` > =20 > const ASSUMED_BYTES_PER_LINE =3D 80; > const ASSUMED_TAB_WIDTH =3D 4; On that topic, may make sense to also fetch the actual terminal width and h= eights respectively (ioctl TIOCGWINSZ). I.e. if terminal is 20 lines high, printing 20 lines is a lot. if it's 80 l= ines high, 20 lines is acceptable. > // unmodified > var_dump(truncate_string("test short string")); > // 5000 'A's followed by "...\n" > var_dump(truncate_string(str_repeat('A', 10000))); > // 100 lines containing "A" followed by "...\n" > var_dump(truncate_string(str_repeat("A\n", 10000))); > ``` I'd wager nobody needs a hundred lines, I'd use inspiration from debuggers = which typically show 5-20 lines max. IF you want to print it all, it's just as easy as `echo $var;` though. So overall: try to make efficient usage of horizontal as well as vertical s= pace while still remaining usable and readable. Bob > Thanks, > - Tyson