Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:108377 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 95615 invoked from network); 4 Feb 2020 15:27:25 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 4 Feb 2020 15:27:25 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 956671804F8 for ; Tue, 4 Feb 2020 05:39: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=-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-ASN: AS15169 209.85.128.0/17 X-Spam-Virus: No X-Envelope-From: Received: from mail-yw1-f48.google.com (mail-yw1-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, 4 Feb 2020 05:39:33 -0800 (PST) Received: by mail-yw1-f48.google.com with SMTP id i126so17608673ywe.7 for ; Tue, 04 Feb 2020 05:39:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:message-id:mime-version:subject:date:in-reply-to:cc:to :references; bh=sg4/UVsf/nzGLC/kaKOYF7JAJkLytndaODnIX/N6ffQ=; b=C455kXHp3iHrveqX9NX4d/zfuliMzl1q6zQcaSwYWkb5TQpVyk+YZJuVIGYOSUQ/d8 k96OcGZ7LUt0p6zr5xo+CFZepIJDTupskoBy1scfXsebBk7Ac2PWT05Je16CXbeUwuSk VdMJpzzUNlqfY2ptUbP6jyvCLmBbX9gwRrpvNlqKbUQfidUqdnq4LJC3LCtNTdUhTXpe VNMZGjPEeHGs4py9Gqr2EBI2FX1tn2Lv9k095Nkn0CkkG5IyCsQ1oy4+OxkCKMYRch3J IW0TrnRzOdPEzqSjPvckAkGIRI74RUFt5lUHv985qLoaJTnELD+v3n99gsbEQarRLf75 QK/Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:message-id:mime-version:subject:date :in-reply-to:cc:to:references; bh=sg4/UVsf/nzGLC/kaKOYF7JAJkLytndaODnIX/N6ffQ=; b=QKIQeqpDb73nOUp/J6pPTDsbbRSoGznUmrY1DikQEaekaQwwD1PzuXiZoRvdfsiWkY cSP57slar45cfzuX6rmdgeSX4i6zQ0yDTkxCnbQezTsiHcDz1LTtfbFhbBrXbyrvQSXG dpfwrDfGyy5vUOMw8VlT1rtor20ai4Wb8XIumjbFRTi5XkYC/reG+qujFCYSvfZ3HA9s //Bj6LcIVh+NK8+zbdvYRywgd4C0EEAucYnbTn5rfMXkKM7KqDy/E+cYq8YmIyDnQ61+ ia+jCA5mZQiFjdT4ZdBESqvjoTsJa9xAWQPhv7JQOg5Pl6PAtEjXWIhoOKiS4fl2m9pk NrNg== X-Gm-Message-State: APjAAAXuVS9LZm0mnZWWypFPRN3Xrr2ey6MR/+TK28DbepbXBYX0CzkA hyaG5Y/T8TGatEu+zgrw8ho= X-Google-Smtp-Source: APXvYqztSzv1y37oQLnBpCl4+CA7+mG5p4jFKgETjlueKd9JRPu9GzxS2mpbZYKx0WkrKBbrQ4CmaQ== X-Received: by 2002:a81:1a0c:: with SMTP id a12mr5529322ywa.218.1580823573300; Tue, 04 Feb 2020 05:39:33 -0800 (PST) Received: from stevensbbookpro.lan (97-95-205-109.dhcp.sffl.va.charter.com. [97.95.205.109]) by smtp.gmail.com with ESMTPSA id a23sm9810040ywa.32.2020.02.04.05.39.31 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 04 Feb 2020 05:39:32 -0800 (PST) Message-ID: <516080A1-D777-49BD-A4A1-9978C2D558CB@gmail.com> Content-Type: multipart/alternative; boundary="Apple-Mail=_C172DA83-3397-470F-B492-B846EC4FA8E8" Mime-Version: 1.0 (Mac OS X Mail 13.0 \(3601.0.10\)) Date: Tue, 4 Feb 2020 08:39:31 -0500 In-Reply-To: Cc: PHP Internals To: Benjamin Eberlei References: X-Mailer: Apple Mail (2.3601.0.10) Subject: Re: [PHP-DEV] [RFC - discussion] __toArray() From: stevenwadejr@gmail.com (Steven Wade) --Apple-Mail=_C172DA83-3397-470F-B492-B846EC4FA8E8 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset=utf-8 > I am open to the idea of having __toArray. I just have a few questions = about the RFC details. >=20 > 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 = you 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. > 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 = and 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 = array 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 = consistent with other magical casting behaviors and I wouldn=E2=80=99t = expect a class implementing __toArray() to be able to be written or = referenced like a traditional array.= --Apple-Mail=_C172DA83-3397-470F-B492-B846EC4FA8E8--