Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112926 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87741 invoked from network); 19 Jan 2021 14:45:59 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 19 Jan 2021 14:45:59 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id CDAFE180503 for ; Tue, 19 Jan 2021 06:25:42 -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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-oo1-f48.google.com (mail-oo1-f48.google.com [209.85.161.48]) (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 ; Tue, 19 Jan 2021 06:25:42 -0800 (PST) Received: by mail-oo1-f48.google.com with SMTP id x203so4941659ooa.9 for ; Tue, 19 Jan 2021 06:25:42 -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=foVMWR9bhiVaHk4ERdm3EqPR1OJ3c6cEeNpOzXDo2+I=; b=aL/5ceVaWlXN/IYjudID+EqS3kr8Il/348hXl1L1qJb1quMuvlL/fDtnSvZgW+Poac 6oUUeiwQSfHvxLYzppvFvaG8vqyeZdsbS5atqntdFx+Gcj2K0K5b/e7LMPsL6TAZ7tzp zPUORfTubO2mYgzRjaUu2CYZEgsbKS+WVGTEcTcF4udY6tJJT2nyQ0uO0BUVDRRAiWAM qcyDva77OpdxQg2PtuUabxCJfoCHlhhHgHwUYXjcyeaQclIJ47YZuR48WTb5k1VFDtkj Drxyh9egyHEkSPoI/mhH/92+Vu/xPwvynYPL+jna/FSdBJ764a396Q5j4UutZIkTpeME rOWQ== 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=foVMWR9bhiVaHk4ERdm3EqPR1OJ3c6cEeNpOzXDo2+I=; b=jWv/GceHxtM5G9umeRUM3TArHaKRIUchOKT5kM+TqnR0g5qsEwG8kcIdl2xu7APwcW yxbrvTXM8rj+J3Aqwv/YDnlxFzYZmK7r8tKNHU1+bv7nlWCR35asW5tYFzM835nTjfV7 QdnxtV7B9THzwaBiWFXxqSWPJ16+fZwshjPlGdalmLCEJkJtuW9J/c9ioC6kdryePqAH 2JRS3hW57p8frpRGMFokDMacY5AQFctGtXPvLyHqTjdHQRua+4TOb9tbkUPDmLYCKAE6 FexpH8KHJNxM+YR62JvCxygpyW7SQPs9LfeTr+X2LZFqMapVJXs44RRU/H4nwHlGTXBr cp/A== X-Gm-Message-State: AOAM531WJW40fzI5BE1KZ17UMpUN1h01Gmp7Cy4gIOa+8XpUMUbg/kAe QJOv2FWWGTQGEd07ng46NgmCMaGXvhINkF+uJEE= X-Google-Smtp-Source: ABdhPJwWo4AypFkARmF3rHwp0EsOyCjQqkTOq42TyIst4+o3HDqSN4ycwtytlTuV45vHApEE6E8o+M9r2NtssoSzNNY= X-Received: by 2002:a4a:db78:: with SMTP id o24mr2987862ood.69.1611066339271; Tue, 19 Jan 2021 06:25:39 -0800 (PST) MIME-Version: 1.0 References: In-Reply-To: Date: Tue, 19 Jan 2021 15:25:28 +0100 Message-ID: To: Nikita Popov Cc: tyson andre , "internals@lists.php.net" Content-Type: multipart/alternative; boundary="000000000000dca8d005b9419c3f" Subject: Re: [PHP-DEV] Proposal: short_var_export($value, bool $return=false, int $flags=0) From: benjamin.morel@gmail.com (Benjamin Morel) --000000000000dca8d005b9419c3f Content-Type: text/plain; charset="UTF-8" > Hi Tyson, > > The formatting of var_export is certainly a recurring complaint, and > previous discussions were not particularly open to changing current > var_export behavior, so adding a new function seems to be the way to > address the issue (the alternative would be to add a flag to var_export). > > I like the idea of the "one line" flag. Actually, this is the main part I'm > interested in :) With the one line flag, this produces the ideal formatting > for PHPT tests that want to print something like "$v1 + $v2 = $v3". None of > our current dumping functions are suitable for this purpose (json_encode > comes closest, but has edge cases like lack of NAN support.) > > Some note: > * You should drop the $return parameter and make it always return. As this > is primarily an export and not a dumping function, printing to stdout > doesn't make sense to me. > * For strings, have you considered printing them as double-quoted and > escaping more characters? This would avoid newlines in oneline mode. And > would allow you to escape more control characters. I also find the current > '' . "\0" . '' format for encoding null bytes quite awkward. > * I don't like the short_var_export() name. Is "short" really the primary > characteristic of this function? Both var_export_pretty and > var_export_canonical seem better to me, though I can't say they're great > either. I will refrain from proposing real_var_export() ... oops :P > > Regards, > Nikita > Sorry for the plug, but you may be interested in getting inspiration from brick/varexporter: https://github.com/brick/varexporter In particular: - uses short array syntax always - doesn't output array keys for lists - can output lists of scalars on one line, under a flag: `INLINE_NUMERIC_SCALAR_ARRAY` - Benjamin --000000000000dca8d005b9419c3f--