Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:112940 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 98616 invoked from network); 20 Jan 2021 16:47:43 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 20 Jan 2021 16:47:43 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 177641804E4 for ; Wed, 20 Jan 2021 08:27:44 -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,RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-io1-f42.google.com (mail-io1-f42.google.com [209.85.166.42]) (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 ; Wed, 20 Jan 2021 08:27:43 -0800 (PST) Received: by mail-io1-f42.google.com with SMTP id y19so47980316iov.2 for ; Wed, 20 Jan 2021 08:27:43 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=benramsey.com; s=google; h=from:mime-version:subject:message-id:date:cc:to; bh=zPg55uzo2OWNIIDx8+lipmGGoTVYTHOzK5/+vShUWPM=; b=NTEKUjmah1GsFPjn7XC3RoHMgCWf6RMn4lm3tTm/QDUukntNXj3SYizBDSqBqpW/Sb Bnuk/HfO7he/yZhJ+dC6OIPewjj0ZvXxYew71a7IPXWs7hCxmbsgEmL6tjPZxHD8WAVU xZ4ZHA01HOEPoEF0TzJ5OszDR8p3Wm+z6ukEHO21JalTGmEKwGMyyKuq4jJEfBY4+Epw ItaIZeaDdOgquH+geLveDSmhs0Gm8pvsgq6SH+1FAa8abLz96+gMzh6gm6guF2J1fMM6 WPAeymcWoNxMFZ0+e/DpNeoALLZCB15Ss1LZQrvAcxhisvhQle0Pq/MrF4HDRPtAvXIA 7+mg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:mime-version:subject:message-id:date:cc:to; bh=zPg55uzo2OWNIIDx8+lipmGGoTVYTHOzK5/+vShUWPM=; b=U8r+dCJuuG2SxzCEUCkH3xeEpiLt6gLHsIw/RN5gHkv0nTQcFcrgbLvqngZM/C+Pno 7NF054pwok7VfOWL6mhFTfcRwNcf/5v8vhqJcEoyPr1dnV2jXZoZTs1sbY6mIFhekzks QAeonQBUwjmdS9QZDQF8DcBUBCr9yuPtuUpx0nehah7qGd5fR1RMhxtvetjJyVPjSaNh IP+ahky9mfxkYJaKewcuQsT4h6JT7j8ln6whC65S822JNZ3zgv83Cm1MoO4ikW6Yuayi c6DnARZXbaarlcKbhQCmnKaNAoXzxpiUUhi0QvdSWR1XRur9uitFKLO+GJ+03Xz0oj70 J6ZA== X-Gm-Message-State: AOAM531Andy4573AkxLYXVYxBnaOP84vjmoMSB/yE9Hv4cm4rJkTvFqM CUPkUqmqZYhxeCDwjobewC4Pf+uAztSnyP5F X-Google-Smtp-Source: ABdhPJyG7frhQ1m1GXaQFqVaQUc0WvA0cvdQCSsyg1tFXLi2fgVrLMp+zQF7Jqyylw5g55MZ5av7lQ== X-Received: by 2002:a6b:cd02:: with SMTP id d2mr7371529iog.4.1611160061571; Wed, 20 Jan 2021 08:27:41 -0800 (PST) Received: from [10.10.42.56] ([96.61.105.82]) by smtp.gmail.com with ESMTPSA id r1sm1031000iot.8.2021.01.20.08.27.40 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Wed, 20 Jan 2021 08:27:40 -0800 (PST) Content-Type: multipart/signed; boundary="Apple-Mail=_40DF7323-D7A2-473F-A334-8129656A870F"; protocol="application/pgp-signature"; micalg=pgp-sha256 Mime-Version: 1.0 (Mac OS X Mail 14.0 \(3654.40.0.2.32\)) Message-ID: <4C7634A2-885B-437B-B765-C82C2B93143B@benramsey.com> Date: Wed, 20 Jan 2021 10:27:39 -0600 Cc: Dik Takken To: "internals@lists.php.net" X-Mailer: Apple Mail (2.3654.40.0.2.32) Subject: __repr() magic method (was Re: Proposal: short_var_export($value, bool $return=false, int $flags=0)) From: ben@benramsey.com (Ben Ramsey) --Apple-Mail=_40DF7323-D7A2-473F-A334-8129656A870F Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > On Jan 20, 2021, at 09:43, Dik Takken wrote: >=20 > On 19-01-2021 16:12, tyson andre wrote: >> It seems inconsistent and prone to bugs when refactoring (e.g. = converting to string and not using the result) >> to have two functions named var_export where one prints by default = and the other doesn't, but otherwise . >> Changing to a different name entirely would solve that, such as = var_repr(), var_representation(), serialize_[value_]as_php_snippet(), = etc. >>=20 >=20 > I am considering to try and introduce a __repr() magic method that is > similar to the __repr__() method from Python. Having a var_repr() = method > which does not use the __repr() method would be confusing. So I would > like to suggest not to use that name. >=20 > As the intent of the resulting string is to obtain PHP code that will > construct the variable, another option might be: var_constructor(). >=20 > Regards, > Dik Takken Taking this to a new thread so I don=E2=80=99t derail the = `short_var_export()` thread. Dik, I like this addition, but I think the name =E2=80=9Crepr=E2=80=9D = might be confusing to PHP developers who aren=E2=80=99t familiar with = Python idioms. PHP function names and coding standards within the = community tend to lean more toward verbosity than terseness, when it = comes to naming things. Perhaps we should follow the lead of `__toString()` and use = `__toRepresentation()`? Maybe also introduce a `Representable` = interface, like `Stringable`? https://wiki.php.net/rfc/stringable Cheers, Ben --Apple-Mail=_40DF7323-D7A2-473F-A334-8129656A870F Content-Transfer-Encoding: 7bit Content-Disposition: attachment; filename=signature.asc Content-Type: application/pgp-signature; name=signature.asc Content-Description: Message signed with OpenPGP -----BEGIN PGP SIGNATURE----- iHUEAREIAB0WIQToXQMR3fpbrPOmEOewLZeYnIwHGwUCYAhZ+wAKCRCwLZeYnIwH G2tnAP4s3PFokCZHUw2ujff6mvfunmXWunkCAiK6hrQB6RvN0gD/ch5mVYVSw77J hybM96GXiL7lk5sru5WksObrlJKmI/k= =SKid -----END PGP SIGNATURE----- --Apple-Mail=_40DF7323-D7A2-473F-A334-8129656A870F--