Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112739 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 19157 invoked from network); 3 Jan 2021 21:09:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 3 Jan 2021 21:09:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 3A8A11804DD for ; Sun, 3 Jan 2021 12:45:45 -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=-1.9 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_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-CO1-obe.outbound.protection.outlook.com (mail-co1nam11olkn2065.outbound.protection.outlook.com [40.92.18.65]) (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 ; Sun, 3 Jan 2021 12:45:44 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=CkYFPGMKJN0s2QGKU7VdJzERrwRDgJ1CnyoW303WFwM6SDW/OLY6L/FUTYqMCCxkdHHO0OF8T2Z3CaoGAra/TaeXdAVRw0GsCUytIAK82CtwBNNSrb6V81iBU5cNGfnOuewgTn97T0+82i9tOOMNqC6akPDFIDVcYkYih1fph0KJ1AmZVYngU7Dq37tdfcNZKAXTpADFG1qDo08qBwBoZhRFcVrcYK6Z0e/KrarfUJjCIGJy9unqiJ6TTUEFlxgkrjKm/tdBCGDdmqrzw/vbczLxB+28pJaQSvoGCnVI7l3l3uAbI5y+LDAFZIJnxgWVa81Ke9VsQHSVjkRyO7TS8A== 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=nsFaxsBaQtkqWLnPnUmZOCVTVwt8Awjw+6VJG4b+Vyo=; b=OygJZjK4Oo44tpRLApuamOiMiBiEsmeRveFSjkWFXCb8OlyrIHEY9vRnqCHGwZuWGMIqjNt+TC2Ha2mso6PWUsDkHnAsEir5rknRa7EGzR31NjpBfuMT9jfoAK2XvdLpSVENhqSHmL2iTKlxIAaPnWVpf4Kl2+Tlbi1n6htb2ld1ljBRBVQuR0ET8dUCEIH0GjfyeMgdhxgtAjBHIE78sz4ZwGhtDyoM3iIbu/tA539dcmMi80YHK21aqEjfSv2dUeomsHwQarVHInpD0FdGo2uLe6LwByUFXJd9ifVO80q4Ld1HbHNOd8Z3vN2zPsQvs2mFdjP6+hNnX3lApxNcEg== 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=nsFaxsBaQtkqWLnPnUmZOCVTVwt8Awjw+6VJG4b+Vyo=; b=gmb16E4NXI7xN7aZVAROq69TjVDyNsLGVlr75dPn6LGeG2Ak0G4bES9UjroPjb6FDIZeTTh8Xs3sNA4rMfNiCv/OkxWJo2aXnHRm0XDHNqvWlrvkmwWPsFJ61L7vwvCwQzj61LILp3xfINShnBZK/HBaBDkBOxSfPXmtKHSd+Z5T+TmQBM/YqxO66n1tANHzQt6qxEYtx15vafKOfvCT8g4xqR19Rvr+GZYDqiRIwcyzlhksbMP4YVMm8SWRG2AKf5ZvRV912FH7sp36vbd6v26DTdk3Ee7xS8QWo+jXaMQmaSPzDt7OThHTykmE/iABwQTjfGSu9AQWJaLlSuPEqg== Received: from DM6NAM11FT053.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4d::47) by DM6NAM11HT146.eop-nam11.prod.protection.outlook.com (2a01:111:e400:fc4d::280) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.24; Sun, 3 Jan 2021 20:45:42 +0000 Received: from DM6PR07MB6618.namprd07.prod.outlook.com (2a01:111:e400:fc4d::53) by DM6NAM11FT053.mail.protection.outlook.com (2a01:111:e400:fc4d::330) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.3721.23 via Frontend Transport; Sun, 3 Jan 2021 20:45:42 +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.3721.024; Sun, 3 Jan 2021 20:45:42 +0000 To: Rowan Tommins , "internals@lists.php.net" Thread-Topic: [PHP-DEV] [RFC] Configurable callback to dump results of expressions in `php -a` Thread-Index: AQHW1x7Yg3FUP/hma0qSEEKC7GDKEqoVDKsAgAAh0ouAASQ4AIAAEnko Date: Sun, 3 Jan 2021 20:45:42 +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:E553A28948402B8F24B7A3515C4159FB90E9F133A4B16CE93D6A3FAC6661A775;UpperCasedChecksum:6A0ECA541456F5BE96CAA8BC1E286CF593652F201062C2101F5FBE0986739F56;SizeAsReceived:7212;Count:44 x-ms-exchange-messagesentrepresentingtype: 1 x-tmn: [ERtyDdn92QJKEfr8H1DERDZfTpS4m7/eO1uqbyYvzf8=] x-ms-publictraffictype: Email x-incomingheadercount: 44 x-eopattributedmessage: 0 x-ms-office365-filtering-correlation-id: 8d02c0f6-f0a5-4a51-fcae-08d8b02889ac x-ms-traffictypediagnostic: DM6NAM11HT146: x-ms-exchange-minimumurldomainage: github.com#4835 x-microsoft-antispam: BCL:0; x-microsoft-antispam-message-info: Ye8gSJrgGYdGgDFPt6PzLnvDbgB1bAiFIKobLinNPjM1W/K70nk4fsH6JH/i/NXzhpkEGu6RootbRt/nPwhaI1p6Ajl9nnBtFjEz5mcZHpunCgkxe3vJ3Pm2Xq1FoRMrlb1POpKjS7Rty4l/K6vnzO2Qni7Vjt6EsP1BGzR9kGnGAHu0cc1vFJgFMTt1/RS3UE3X3tRIKzMhqdRFNtZY92Maes/4ngL7as9b39CXbfExcdb0K4xBaJApC//LN9t9O3otv+nZtBbbgnNB9DBsKTMorpN7VWrF1uZ2Ta5Kih4= x-ms-exchange-antispam-messagedata: IE54cCBoxGXbZUrNKm1750T4ekoHi70/IStQQgSaYWvaWNzWYMoy9WrGjxFOFZdqFw90RBugkw7QUUdpNWFVfBWMBzo1Kt1ta0elMqYU2787hA7EZGBNM6Jv2yGPmLVzZXjTtzSMOmbcFslH6JtUYg== 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: DM6NAM11FT053.eop-nam11.prod.protection.outlook.com X-MS-Exchange-CrossTenant-RMS-PersistedConsumerOrg: 00000000-0000-0000-0000-000000000000 X-MS-Exchange-CrossTenant-Network-Message-Id: 8d02c0f6-f0a5-4a51-fcae-08d8b02889ac X-MS-Exchange-CrossTenant-originalarrivaltime: 03 Jan 2021 20:45:42.7471 (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: DM6NAM11HT146 Subject: Re: [PHP-DEV] [RFC] Configurable callback to dump results of expressions in `php -a` From: tysonandre775@hotmail.com (tyson andre) Hi Rowan Tommins,=0A= =0A= > > - The benefit is that dumping the result of expressions improves the de= fault experience.=0A= > >=A0=A0=A0 psysh wouldn't be installed by default when a new developer is= learning php through the php manual, or when sshed into a remote server.= =0A= > =0A= > It doesn't feel to me that you've really answered Nikita's question: if = =0A= > all the code using these hooks is going to be distributed as userland =0A= > code anyway, then they're not going to improve the default experience.=0A= =0A= I was saying that I'd planned to propose defaults if this passed.=0A= __debugInfo() is a slight improvement, but the human-readable representatio= n of an object isn't always the same thing as the debug representation of t= he object.=0A= A human-readable representation might be `Point(x: 1, y: 2)`, where var_dum= p or var_export(`__set_state`)=0A= is much longer, and I don't believe var_dump is a one size fits all solutio= n for both simple and recursive data structures,=0A= especially since `__debugInfo` predates the repl.=0A= =0A= ```=0A= php > class Point { public function __construct(public int $x, public int $= y) {} }=0A= php > var_export(new Point(1, 2));=0A= Point::__set_state(array(=0A= 'x' =3D> 1,=0A= 'y' =3D> 2,=0A= ))=0A= ```=0A= =0A= > It feels like we need to go in one of two directions:=0A= > a) Build a full-featured official REPL with all of these improvements =0A= > completely implemented out of the box. Limited extension hooks might =0A= > still be desirable to build custom versions for frameworks etc, but they = =0A= > could be more targeted - for custom input, it could be "register =0A= > meta-command"; for custom output, we already have __debugInfo() at the = =0A= > class level.=0A= =0A= I'd be happy as long as we made progress on improving the interactive shell= .=0A= =0A= Psysh is 2.4MB as a compiled phar release and larger if distributed with li= brary/application releases (e.g. on remote servers).=0A= default extension hooks would likely be much smaller.=0A= =0A= > b) Expose the magic behaviour needed for something like PsySh to do =0A= > everything `php -a` already can, and leave the rest to userland. So far, = =0A= > the only mentioned requirement is a special form of eval() that swallows = =0A= > fatal errors.=0A= =0A= That may or may not be possible to do through creating a new `unsafe_eval` = PECL (or only exposing it for interactive sessions) - I'd have to check.=0A= Something like `unsafe_eval(string $code, array &$variables): mixed result`= (or throw UnsafeFatalError)=0A= The usual caveats about not using it in production would apply - the php co= mpiler treats eval differently in that it has access to the caller's scope.= =0A= =0A= https://github.com/bobthecow/psysh/blob/master/src/ExecutionLoopClosure.php= uses eval(),=0A= but there's actually a lot of heuristics to avoid calling eval() on code wi= th common known fatal errors.=0A= (it uses the readline/libedit PHP module if it's available, but doesn't loa= d readline_cli.c)=0A= =0A= The ext/readline/readline_cli.c overrides `EG(bailout)` with zend_try macro= s to recover from fatal errors=0A= =0A= ```c=0A= zend_try {=0A= zend_eval_stringl(code, prompt_end - prompt_spec - 1, NULL, "php promp= t code");=0A= } zend_end_try();=0A= ```=0A= =0A= > My feeling is that the current mood of the community favours (b) rather = =0A= > than (a); the most obvious example is that PHP used to bundle a PEAR =0A= > executable, but Composer remains an entirely external project. Is there = =0A= > a reason not to aim for the same "de facto standard" for a REPL?=0A= =0A= Even if we do start distributing a better alternative shell with php or end= orsing an alternative in docs,=0A= it's still possible to incrementally improve `php -a`=0A= =0A= It seems like a significant missing feature to omit printing expression res= ults from `php -a`;=0A= people who do use `php -a` may wish to continue using=0A= that feature set (e.g. `#setting_name=3Dvalue` to set/dump ini variables) b= ut still benefit from minor improvements such as this RFC.=0A= https://github.com/bobthecow/psysh/issues/462 mentions psysh isn't a drop-i= n replacement.=0A= =0A= E.g. on shared hosting or when debugging on a remote host, it may be inconv= enient to download psysh and faster to use `php -a`=0A= =0A= https://www.php.net/manual/en/features.commandline.interactive.php only men= tions `php -a`.=0A= Perhaps it should mention external userland shells with a note that they're= developed independently=0A= if the REPL rarely receives updates in favor of other functionality.=0A= =0A= - Someone learning from the php.net manual or a tutorial with minimal depen= dencies wouldn't install psysh right now.=0A= =0A= Aside: the php manual doesn't mention composer except in a few PECL extensi= on docs,=0A= but people seem to figure out how to use composer out of necessity and libr= ary installation docs.=0A= Interactive shells wouldn't be as advertised=0A= =0A= Cheers,=0A= -Tyson=0A=