Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:98623 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 20048 invoked from network); 24 Mar 2017 19:04:38 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 24 Mar 2017 19:04:38 -0000 Authentication-Results: pb1.pair.com smtp.mail=nikita.ppv@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=nikita.ppv@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.128.182 as permitted sender) X-PHP-List-Original-Sender: nikita.ppv@gmail.com X-Host-Fingerprint: 209.85.128.182 mail-wr0-f182.google.com Received: from [209.85.128.182] ([209.85.128.182:36480] helo=mail-wr0-f182.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 61/F8-40046-0CD65D85 for ; Fri, 24 Mar 2017 14:04:34 -0500 Received: by mail-wr0-f182.google.com with SMTP id u108so7562870wrb.3 for ; Fri, 24 Mar 2017 12:04:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=61qLQsPhzIkgg/fm8+vo/OmsEfL+H4XaCuOawPSaHbQ=; b=Cy/fS3DYl2dDUucdQAaHbx68SE5pN7YHPvSSNdrYr3G+X5k0fcbcpruXCFvey9N6q1 F+yZlZYRwfC7kvshTsgutrigDQ/x/FHYUNw+BIj3inPqG1qqPMHJaJX4FoMfNpR60eNg wxDrdpg6HBlH6wcwz1hanVjf72kjCOzR/HNQ96mBQyxGP82Anz7EOexCOryNuu+KDEW0 g0wfHyO8GG8h6IZ5tGNr3n/iq6cszJI/ZgSeA3GpfRW4ETvRDpnpGpwgYPizHzqXw92T ung4hk+q178lWxY9qC2ukx0C/G8h6qskr7dX1Kf8QDjOVF25Z8C0Jbyf7Nks673JVPHT KGZw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=61qLQsPhzIkgg/fm8+vo/OmsEfL+H4XaCuOawPSaHbQ=; b=cPUg7w0T/Cm1pcuIPilvDqK/o2Icyx3goX9WhxS3AWQLerZ3pqBiOWsSI2I5tw6uC0 WEj8+MWATv8o3apRCPk7ywj4A11XzFKLhyH0VXTryBBdpHIL1Ieg6KGSjME/vcHLmET/ BAkqiQJRZsD45zWhHRzO3wfX5Vb4PZq99/InWXDhb1q+fkcibpOUHdqvanNrNsfG2ftu gOscmPLIT1N7eYshX1G+9BvzQSylf12LYody63rCpAodPc14Yr6SAkgvNgufuP8U5li4 bGWKdKaWKfOgVffAX77Hud4i5F5yyABDwWI4hNifkWjx30WM67pKxigawfOq/F3BYA/H R2/w== X-Gm-Message-State: AFeK/H0mjLaV0rJpsWwRgBhtXbn74gsXU8hQ4og2YE5CeKUYzCAsks+tOh7lhSWUxlLUg4VH25UpreEhvU5FpA== X-Received: by 10.223.182.133 with SMTP id j5mr10306813wre.19.1490382266894; Fri, 24 Mar 2017 12:04:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.223.170.216 with HTTP; Fri, 24 Mar 2017 12:04:26 -0700 (PDT) In-Reply-To: References: <16.06.40046.20A35D85@pb1.pair.com> Date: Fri, 24 Mar 2017 20:04:26 +0100 Message-ID: To: Levi Morrison Cc: Andrea Faulds , internals Content-Type: multipart/alternative; boundary=f403043892d4991066054b7ea9f5 Subject: Re: [PHP-DEV] Re: TOKEN_AS_OBJECT for token_get_all() From: nikita.ppv@gmail.com (Nikita Popov) --f403043892d4991066054b7ea9f5 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable On Fri, Mar 24, 2017 at 5:26 PM, Levi Morrison wrote: > On Fri, Mar 24, 2017 at 9:23 AM, Andrea Faulds wrote: > > Hi Nikita, > > > > Nikita Popov wrote: > > > >> I'd like to add a new TOKEN_AS_OBJECT flag to token_get_all(), which > >> returns an array of PhpToken objects, rather than the mix of plain > strings > >> and arrays we currently have. The PhpToken class is defined as: > >> > >> class PhpToken { > >> public $type; > >> public $text; > >> public $line; > >> } > > > > > > Rather than adding a flag to token_get_all() to return objects, you cou= ld > > potentially instead make an equivalent static method on PhpToken > > (PhpToken::getAll() perhaps). That would avoid mixing =E2=80=9Cobject-o= riented=E2=80=9D > and > > =E2=80=9Cprocedural=E2=80=9D styles, though I don't know if it matters.= It seems cleaner > to > > me. > > > > Thanks! > > > > -- > > Andrea Faulds > > https://ajf.me/ > > > > > > -- > > PHP Internals - PHP Runtime Development Mailing List > > To unsubscribe, visit: http://www.php.net/unsub.php > > I prefer a distinct function/method from `token_get_all`. I don't see > the value in having a return value that differs so much based on a > passed flag. I don't care so much about a function vs static method; I > just oppose the additional parameter to `token_get_all`. > > I like the idea very much overall aside from that detail. > token_get_all() already has a $flags parameter controlling its output. Currently only the TOKEN_PARSE flag is supported, which changes the interpretation of certain tokens. In a previous thread on this topic Sara suggested another flag (something like TOKEN_ALWAYS_ARRAY) which makes the output of token_get_all() consistently use arrays. I think handling this as a flag is entirely reasonable, and by analogy, handling the object mode as a flag is also reasonable. In the end, these are just minor variations on the output format (minor relative to the very complex primary functionality of the function: lexing). Another precedent is the json_decode() option to use arrays or objects in the return value. Regards, Nikita --f403043892d4991066054b7ea9f5--