Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112971 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 40617 invoked from network); 24 Jan 2021 14:01:33 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 24 Jan 2021 14:01:33 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 353741804C6 for ; Sun, 24 Jan 2021 05:42:31 -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, 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-wr1-f46.google.com (mail-wr1-f46.google.com [209.85.221.46]) (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 ; Sun, 24 Jan 2021 05:42:30 -0800 (PST) Received: by mail-wr1-f46.google.com with SMTP id a9so9609237wrt.5 for ; Sun, 24 Jan 2021 05:42:30 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=gZWJG4ZcNuy+AG6Fzkxmif2zx9JX11AnOXDIHyNqRFo=; b=muLgZd9vMy4whzrKyDQBSmE6j0Gd+3mmLnUFps0noeg5pu+DFy77tpctQA9Oc4PsV7 hVvNnOvHNI6SRP+ICjxjf9/5LrEvwqLO/gpFG+3BcN4/0i6Ei3CziigMDwGCIdW/YQkO QyfDFm/cMXqp+uFAdxzzKbcgsF/vsANGtjfHiZPPRtUV3wyLwotT5Vc8svCeTCi6hUlV uUK0YTQVGlWzCFbAl0jmAbm+t+9bX8gpWlN+qqJBOg/ptAkuV+ha9kFagcWJ0U4sc8KV iSyTmRNUI3RgGqRUI/Rhe1OWaoQ8iyyiHSgxa+D209Rhus5kHTg3ZLxAdABC2qLVnHGI NZAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=gZWJG4ZcNuy+AG6Fzkxmif2zx9JX11AnOXDIHyNqRFo=; b=fLLYhR0Y5wuZpHVSy1PHqfsNecj0sZbVYl8NLwYZS0bQEJg2ceBsEEQhkzcvV98/gj WgcaouqUEWWZ1KJGrz7z63x0A1dR5ZDHUy0M3L88dORVgduLWkumOR5DWQXScUxtgL8W LxXWck7YbB7Pyq00CDAcCUHNgnwZzLm2UDJ1ISKruo4ZkQtbsYo1Rsh9DVLLKF80w6D0 0y3FlT4ICsVZT4X+XoGVK68zyu5cv54QQDo+FXY8Vsltq10g8OTupV9h4rnNp+aX4JDI d9mA6RjSReLAkRlT9uynhNOMTDchHeh6wo4d2kL+b6U+OmMg/mnbes82tst9pK4Il9QI 61Pg== X-Gm-Message-State: AOAM530s+lAL/tBdjb3VIw/sycQLD1eIGbNWxELbCc53fk7Ouc1q9NXD rvsftNiZpgjkPaJstbrTBX8LUipBGwg= X-Google-Smtp-Source: ABdhPJyYcpBPS/2VXdMMipIoU5F9d1WOcEwKSLJU3SG9kxVncHwnvyTQ/BSh77qy37O2/hDmdZeGJQ== X-Received: by 2002:adf:9b92:: with SMTP id d18mr1637793wrc.170.1611495749294; Sun, 24 Jan 2021 05:42:29 -0800 (PST) Received: from [192.168.0.22] (cpc104104-brig22-2-0-cust548.3-3.cable.virginm.net. [82.10.58.37]) by smtp.googlemail.com with ESMTPSA id l20sm20600739wrh.82.2021.01.24.05.42.28 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sun, 24 Jan 2021 05:42:28 -0800 (PST) To: "internals@lists.php.net" References: <5ae166a8-378e-b3bc-056a-8ccf4f3a1ddd@gmail.com> Message-ID: Date: Sun, 24 Jan 2021 13:42:27 +0000 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.6.1 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit Content-Language: en-GB Subject: Re: [PHP-DEV] [RFC] var_representation() : readable alternative to var_export() From: rowan.collins@gmail.com (Rowan Tommins) On 23/01/2021 21:07, tyson andre wrote: > I've added those to https://wiki.php.net/rfc/readable_var_representation#when_would_a_user_use_var_representation > , including when I think the VAR_REPRESENTATION_SINGLE_LINE flag would be useful to users. Thanks, it's good to at least know your opinion on this, even if I don't fully agree with it. :) > var_representation may be useful to a user when any of the following apply: > > - You are generating a snippet of code to eval() in a situation where the snippet will occasionally or frequently be read by a human (If the output never needs to be read by a human, `return unserialize(' . var_export(serialize($data), true) . ');` can be used) As far as I know I have never had any reason to generate code and then eval() it, and can't think of a situation where I ever would. If I wanted a machine-readable output from a variable, I would use serialize() or json_encode(). That's not to say that there aren't cases where those requirements do happen, but I think it is a very niche use case to dedicate two different built-in functions to. > - You are writing unit tests for applications supporting PHP 8.1+ (or a var_representation polyfill) that test the exact string representation of the output (e.g. phpt tests of php-src and PECL extensions) Since test output doesn't need to be executable, I would have thought var_dump would be more appropriate than var_export here. Checking on php-src master, this does seem to be the case in the majority of tests: - var_export appears 703 times in 136 different *.phpt files (0.8% of files) - print_r appears 827 times in 342 different *.phpt files (2.1% of files) - var_dump appears 33503 times in 9599 different *.phpt files (59.7% of files) So if we want to improve anything for that use case, we need to improve or replace var_dump, not var_export. > - You need to copy the output into a codebase that's following a modern coding style guideline such as modern coding guidelines such as PSR-2. It also saves time if you don't have to remove array keys of lists and convert array() to []. Trying to match any particular coding style seems rather outside the remit of a built-in function - do we need flags for tabs vs spaces, trailing commas, etc, etc? Surely it's simpler for users to take the existing var_export format and use their IDE or dev scripts to re-format it to taste. Regards, -- Rowan Tommins [IMSoP]