Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108380 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 99292 invoked from network); 4 Feb 2020 15:31:24 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Feb 2020 15:31:24 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id E878E1804F8 for ; Tue, 4 Feb 2020 05:43:34 -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=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,HTML_MESSAGE,RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2, SPF_HELO_NONE,SPF_NONE autolearn=no autolearn_force=no version=3.4.2 X-Spam-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (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, 4 Feb 2020 05:43:34 -0800 (PST) Received: by mail-wm1-f41.google.com with SMTP id t14so3701930wmi.5 for ; Tue, 04 Feb 2020 05:43:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=beberlei-de.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=uLYGy1gyocBvhXbPTWjbZ/KtnZEFxAE0j5mykXoqmPU=; b=eQ9GKsmwDT5MM3lZ1BxjOC1dKjUw98Cvk4Qa6S0vnoqkbTML9MZIWS/i0/gQBun64z 1tiiTfzWdodEOqMTN359FIsjK2p+nXRGAImKkalnXQKVYGOHxPdcMNfV/4ciPlpgslvQ x15cdrqMfdv/h2NSoBn2RLtMJyP7oiq5Oo/g2xOPDABMDzORFXoWQdgRkwXhacFafLpu lAhsIJ4MD1HdPl4X1o/dwA0jMe85jSu0iIVuXIOBZxfydGSFYRb3KA7wHAPlWwcFXMEM CHQ/vTh1V19vHNP6h6MlJwuHW/ef5QXyeH3FHlB67bA6Q56ojs9U6EYCLyzNqBEypl47 yLog== 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=uLYGy1gyocBvhXbPTWjbZ/KtnZEFxAE0j5mykXoqmPU=; b=mJZTdGX2Sjjc2dwvWf4Lu5bRbP79APX375p4E412+S7q3TEfYDkXF84Iv6tubfZv+D PA/H9hgvPvrYv6+k+JaDka5/Ja+lPO0Po8XYq+w4WozG/Hz8yI9kabVSIcaO9zfpA4As 8cXi0P/pvtUiqLuMmvms8h9/nUzLQN4+Y1/+K3KzySgF+J3prWDd25395FqJ09rdy/MD LmvpOqXjKwFw50Ei/giV1JNrrUwWZz6xP7Atp+NXDCWCCx5YsAdySECPqhZmxNdhf3gV 3YU70w9N066VVXjNS6qDy5aLTnSYWKMK7CwNWqIIDy1q+pbsSfc0d1r29xSGktAIHkra 7IhA== X-Gm-Message-State: APjAAAW9OowzruLjW6EI8oMg/07NW3vmYHcxl1HfyOXpeLaqLJJvZ8J8 KKHYavzzF694ucEyNc+ivaQkZ1VTe+4gkyQa1SS6fQ== X-Google-Smtp-Source: APXvYqzn65PeDFYusVrnsxVv/WrsAU+31kNmsDVLjpH1dSOf/jCAKoZz4SKpoX4RCICXKxtAQxSSXZTGTzp53IWSKI8= X-Received: by 2002:a1c:20d6:: with SMTP id g205mr6180874wmg.38.1580823813180; Tue, 04 Feb 2020 05:43:33 -0800 (PST) MIME-Version: 1.0 References: <516080A1-D777-49BD-A4A1-9978C2D558CB@gmail.com> In-Reply-To: <516080A1-D777-49BD-A4A1-9978C2D558CB@gmail.com> Date: Tue, 4 Feb 2020 14:43:21 +0100 Message-ID: To: Steven Wade Cc: PHP Internals Content-Type: multipart/alternative; boundary="000000000000d65cd9059dc03918" Subject: Re: [PHP-DEV] [RFC - discussion] __toArray() From: kontakt@beberlei.de (Benjamin Eberlei) --000000000000d65cd9059dc03918 Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Tue, Feb 4, 2020 at 2:39 PM Steven Wade wrote: > > I am open to the idea of having __toArray. I just have a few questions > about the RFC details. > > 1. print_r($object) would somehow call __toArray you say. Why would it > cause a cast when nothing else is cast? I would prefer print_r((array) > $person); > > > Originally I intended the proposal to be specific to user casting like yo= u > suggested but when writing the RFC I decided to pursue making the magic > method and casting more in line with the behavior of __toString(). For > example, when an object implements the __toString() method and you simply > =E2=80=9Cecho $obj=E2=80=9D PHP automatically casts the object for you. > Yes, i see that it auto casts when you typehint for "array". print_r argument is not array but mixed, so it should not cast the object to array there. > > 2. In the parameter and return type examples you should add > declare(strict_types=3D0); so it's clear this only works in weak mode. > > > I think this is a good idea. I hadn=E2=80=99t looked into strict_types an= d how it > handles strings and their casting. Thanks! > > 3. The weak point of this proposal is the by reference handling for sort > et al. Counterpoint: if you pass a variable to preg_match, then matches > gets converted from anything to array, so i believe by reference casting > should change the original value (https://3v4l.org/XUJ5m). This is weird, > but consistent. > > > The proposal states that =E2=80=9Carray functions that operate on an arra= y by > reference such as sort or shuffle will not work on an object > implementing __toArray() under this proposal=E2=80=9D, and IMO that is co= nsistent > with other magical casting behaviors and I wouldn=E2=80=99t expect a clas= s > implementing __toArray() to be able to be written or referenced like a > traditional array. > Passing an object with toString by reference will change the original variable: https://3v4l.org/77lov --000000000000d65cd9059dc03918--