Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108982 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 89457 invoked from network); 11 Mar 2020 17:38:30 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 11 Mar 2020 17:38:30 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 99F291804D0 for ; Wed, 11 Mar 2020 08:59:42 -0700 (PDT) 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,RCVD_IN_DNSWL_LOW,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS11403 66.111.4.0/24 X-Spam-Virus: No X-Envelope-From: Received: from out1-smtp.messagingengine.com (out1-smtp.messagingengine.com [66.111.4.25]) (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 ; Wed, 11 Mar 2020 08:59:41 -0700 (PDT) Received: from compute7.internal (compute7.nyi.internal [10.202.2.47]) by mailout.nyi.internal (Postfix) with ESMTP id B30E6223A9 for ; Wed, 11 Mar 2020 11:59:40 -0400 (EDT) Received: from imap26 ([10.202.2.76]) by compute7.internal (MEProxy); Wed, 11 Mar 2020 11:59:40 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-transfer-encoding:content-type :date:from:in-reply-to:message-id:mime-version:references :subject:to:x-me-proxy:x-me-proxy:x-me-sender:x-me-sender :x-sasl-enc; s=fm2; bh=T3fjQAHrzVBsIjtP/cXjD1LuKeim8cHMU8/iPl8Y1 Zo=; b=DMzsALlaChop48Mug2VZbztphdsTCvwavxNBRoAtzSZdr8lTagvMQgpZb OsnkMyx0n5VOP9HLM/NVYDTjttQoZoMSBA95/oX4E8IFV48x4J+87c8yCYY9oBo9 /JqW8dhUnbUQkNTzLndoJ8d5kM3hYwOczqvrbWpAmyn0PU3mhWZuC5kzH7XgmlRY qPPTuxpYspLwEy4Xu8qVP1pVAYomjC5ciBcyAhY1RWYtTKxc++oUiV0Apm/6V5S1 O9vdoSoyVakNmEFnHhzD5PJ8E3Z9OY4bjOq3Ajq0OZ0m5RIa7ymOwMXes+L4MdGf m6oZJC2U2VFq2N1KNZ78X+flfiuZw== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgedugedruddvvddgkedvucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucesvcftvggtihhpihgvnhhtshculddquddttddmne cujfgurhepofgfggfkjghffffhvffutgfgsehtqhertderreejnecuhfhrohhmpedfnfgr rhhrhicuifgrrhhfihgvlhgufdcuoehlrghrrhihsehgrghrfhhivghlughtvggthhdrtg homheqnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehmrghilhhfrhhomhep lhgrrhhrhiesghgrrhhfihgvlhguthgvtghhrdgtohhm X-ME-Proxy: Received: by mailuser.nyi.internal (Postfix, from userid 501) id 579E014200A2; Wed, 11 Mar 2020 11:59:40 -0400 (EDT) X-Mailer: MessagingEngine.com Webmail Interface User-Agent: Cyrus-JMAP/3.1.7-991-g5a577d3-fmstable-20200305v3 Mime-Version: 1.0 Message-ID: <41f72798-b464-4ae9-8b57-c3b2b984f39c@www.fastmail.com> In-Reply-To: References: <1715830.3Z3xILz1Hf@mcmic-probook> <8165930.V9hoPP6r1K@mcmic-probook> Date: Wed, 11 Mar 2020 10:59:19 -0500 To: "php internals" Content-Type: text/plain;charset=utf-8 Content-Transfer-Encoding: quoted-printable Subject: Re: [PHP-DEV] [VOTE] Object-based token_get_all() alternative From: larry@garfieldtech.com ("Larry Garfield") On Wed, Mar 11, 2020, at 4:57 AM, Nikita Popov wrote: > On Tue, Mar 10, 2020 at 5:19 PM C=C3=B4me Chilliet < > come.chilliet@fusiondirectory.org> wrote: >=20 > > Le mardi 10 mars 2020, 15:53:41 CET Nikita Popov a =C3=A9crit : > > > Would __toString() return $token->text? I'm not strictly opposed t= o this, > > > but I'd be hard pressed to think of a situation where I would pref= er > > > writing (string) $token over $token->text. Generally, the less mag= ic the > > > better :) > > > > My idea was that since tokens are parsed from a string it should be = easy > > to write a string back with them. > > I do not have an obvious usecase but the idea is doing stuff like > > > > if ($token.is('function')) { > > echo "public $token"; > > } else { > > echo $token; > > } > > > > Am I right to assume that with __toString the same as ->text we=E2=80= =99d have > > implode('', PhpToken::getAll($code)) =3D=3D $code ? > > > > This would allow: > > $tokens =3D PhpToken::getAll($code); > > // Modifications on $tokens > > $code =3D implode('', $tokens); > > >=20 > Yes, that would work. It's not much harder without __toString though: >=20 > $code =3D implode(array_column($tokens, 'text')); >=20 > Does anyone else have thoughts on whether PhpToken should implement > __toString() or not? >=20 > Nikita I forget who it was but someone on the list a while back offered a heuri= stic of "__toString should be used iff there is one and only one logical= string representation of a value, because the value is conceptually jus= t a string with extra metadata on it". That sounds like a really solid heuristic to me. In this case, I think = yes, ->text is the only reasonable thing to produce for __toString(). =20= Or perhaps this is a good use case for "you can use a subclass, do that"= if there's any good reason to not have it just be ->text. --Larry Garfield