Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:113084 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 71547 invoked from network); 4 Feb 2021 20:09:54 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Feb 2021 20:09:54 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 946E6180504 for ; Thu, 4 Feb 2021 11:53:41 -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.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lj1-f179.google.com (mail-lj1-f179.google.com [209.85.208.179]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Thu, 4 Feb 2021 11:53:41 -0800 (PST) Received: by mail-lj1-f179.google.com with SMTP id l12so4925605ljc.3 for ; Thu, 04 Feb 2021 11:53:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=NwNvmvbZ+rU7gqAWJepa2V4aZ2TO8u3M+NTwuggZVxs=; b=FLMLswBp79SvoAjMGaO2hTvhx1MBFlP5gN/WADKwRDUnOauknB5EfTTAEmmlm/4yKA B0p+4EjiKgDyeGQKwcRwq65eVGf+N4bKPqlkiBKAH8aNd1XBB+LKoLa2s205H8UZYGEN MzT9n1EjoXDq5A/wuNHOr/OrQxM4ACpZs5YIXo6fTKkDgOwK2qFGIwvE+wdKQeSC6B3Q u20wF+LF5cLzBo/EPGtjTWW9cT4vHjQSs9G9mm+gNs3sr+Fl8lQSNBxu9yjbuw4nUZlT PaQ2LW5LJzddUqycw6DBB/eH7d0sHeFySccnUn8aPnoxwz3UQBmZPph1kvvQdI0eiCEV 7/jg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=NwNvmvbZ+rU7gqAWJepa2V4aZ2TO8u3M+NTwuggZVxs=; b=hlt3LfOdA8DF6IQIVzUntzls+ng8EACPfEdI9m4YlmIaZcPdY5QZBZBsQhjNl6LMOb Qf4bf/Q37XH7J5pUByZC7owsscRH9LeuUD5Tosi98SWvG4127j6rx7sK9m7VUIyE2PmM BwGn+1tPGaKB0solpHSjAyMNEgbrUBaJU1TEAT7DkOV7t8Td2R+l+GBLBb8XLoiFznUA Q4YHfmCjZ+GivZpTt+caGGJKMY7fEp27F6jR1YdgZxAOP2OPUiVzHlvV9rNWeQkQfcNz aVTygjbr69dyMMZGhMCgqPLQYdlrzboSsH4H2VMz1r390UorsYeaKfqmQE9n+dMQ+M8Y 2tDA== X-Gm-Message-State: AOAM533ID6ojbthRFtkaXkkylDlgGiOU5rifHjziDQCkEZol2DIXyxjs riPd7oUqNQwKTOtTJITh2o8JSEtooy0APOUQrXE= X-Google-Smtp-Source: ABdhPJxvMrUvEa8Oq1l3pIQywlo846yv6TJiNj4b4brnNraBs8yA7SldIXMVSNmtr2I3TVFbneDDDrQOLfICcmmzLRU= X-Received: by 2002:a2e:7614:: with SMTP id r20mr580225ljc.93.1612468419526; Thu, 04 Feb 2021 11:53:39 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Thu, 4 Feb 2021 20:53:23 +0100 Message-ID: To: tyson andre Cc: "internals@lists.php.net" Content-Type: multipart/alternative; boundary="0000000000005b82e005ba880f4b" Subject: Re: [PHP-DEV] Re: [RFC] var_representation() : readable alternative to var_export() From: nikita.ppv@gmail.com (Nikita Popov) --0000000000005b82e005ba880f4b Content-Type: text/plain; charset="UTF-8" On Thu, Feb 4, 2021 at 3:36 PM tyson andre wrote: > Hi internals, > > > I've created https://wiki.php.net/rfc/readable_var_representation based > on > > my original proposal in https://externals.io/message/112924 > > > > This RFC proposes adding a new function `var_representation(mixed > $value, int $flags=0): string` > > with the following differences from var_export: > > > > 1. var_representation() unconditionally returns a string > > 2. Use `null` instead of `NULL` - lowercase is recommended by more coding > > guidelines (https://www.php-fig.org/psr/psr-2/). > > 3. Change the way indentation is done for arrays/objects. > > See ext/standard/tests/general_functions/short_var_export1.phpt > > (e.g. always add 2 spaces, never 3 in objects, and put the array > start on the > > same line as the key) > > 4. Render lists as `"['item1']"` rather than `"array(\n 0 => > 'item1',\n)"` > > > > Always render empty lists on a single line, render multiline by > default when there are 1 or more elements > > 5. Prepend `\` to class names so that generated code snippets can be > used in > > namespaces without any issues. > > 6. Support `VAR_REPRESENTATION_SINGLE_LINE` in `$flags`. > > This will use a single-line representation for arrays/objects, though > > strings with embedded newlines will still cause newlines in the > output. > > 7. If a string contains control characters("\x00"-"\x1f" and > "\x7f"(backspace)), > > then represent the entire string as a double quoted string > > escaping `\r`, `\n`, `\t`, `\$`, `\\`, and `\"`, in addition to > escaping remaining control characters > > with hexadecimal encoding (\x00, \x7f, etc) > > > > This is different from my original proposal in two ways: > > 1. The function signature and name changed from my previous proposal. > > It now always returns a string. > > 2. Backspace control characters (\x7f) are now also escaped. > > A reminder that voting on the var_representation RFC starts in a day. > This RFC proposes adding a new function `var_representation(mixed $value, > int $flags=0): string` with multiple improvements on `var_export()`. > > Any other feedback? > > Thanks, > - Tyson > Given the recent discussion in the interactive shell thread, I think you should consider whether the new function could also be expanded to serve that use case. I think that if we're going to add one more dumping function to the 4 we already have, it better cover all the use-cases we have. The "limited size dump" doesn't really fit in with "dump is executable PHP code", but if I understand correctly, executable PHP code is not the whole goal of the proposal. Regards, Nikita --0000000000005b82e005ba880f4b--