Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105594 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 41708 invoked from network); 4 May 2019 19:33:45 -0000 Received: from unknown (HELO mail-it1-f171.google.com) (209.85.166.171) by pb1.pair.com with SMTP; 4 May 2019 19:33:45 -0000 Received: by mail-it1-f171.google.com with SMTP id v143so13913381itc.1 for ; Sat, 04 May 2019 09:36:56 -0700 (PDT) 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=LmUV7Lb8OLAh2ywspBz3njRtVlt79UnMRfxyvMFbQ+M=; b=c9j4m4nqy5ixOo1V4/AjaVyjRgv/9XoCqQvx4+RSHXiotFQnBu4bBtp8vEHMSoClJV DMILPPyRfUt/62HoPKUjBPopC8xl5rITFzbf8CzFegnaoG1/GnwZbXE+S+e2+KOVoZey Sbf7/59Zd3ub23XA3SluJ5S/9JyTvPx++FX373h2N8wUaBylgFVRa72iCFeuvQ8LErYR N9QrEfdArRfbvjaviOGbxNAwOfwYExrKD7SEOHI4KrhFiO5mGoV3pwV9PTMV07BmMzuu N4Sm8vbwIi6pKz38ZDtBovEfhyjYQ0wtvScb5nSjLxnXNeYfi3RGZ4/8swR1Ek7kx7EL oWMg== 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=LmUV7Lb8OLAh2ywspBz3njRtVlt79UnMRfxyvMFbQ+M=; b=aOi3zLzo88QPuA+gvO2f+ej25Jv1yXtFKXPmWHYaDu1XRpQKaBUymR3SMXAzLs2Ugu v60lTJzD0Qj1phaVIE37sUVqiToj03nyioHcilpknEPnva3UOQf7QEUFos/ugAgOURIo kGC0uFd4RjbjIu1Zlao8lTRUQaFNVnSz+VplN75v7QaQM3OZ+gHMGPhF5AlpFSIjMlRR N/PuU+coCiJNFaJ33dwdBemjbYjfHCZBkLp3R8ihnFSB5gkV62x2dij9j6LeNrHoQ/OQ nnwdHK6o3rFSvVoAjo7u3G7AcCavMHUQztbbtUynrr2g+aVyfSUrDFYdtQQA4FgZa2WX ChLg== X-Gm-Message-State: APjAAAVwCVnAVuyHnvPuoqHe9R2h3ZyEGiSef9eIzp7yWxn+vC2NTDqC XUy5BPY6qh+GU+ZsHuUX0yAAH75BrzfXvI7+uqs= X-Google-Smtp-Source: APXvYqx9k5Xy+yIRHq3B9DFBuTYjdWR/j91cIILYjd2oKDvS+t64pR+y7E3QHuIHe/ljhjZoYmMHO6ZSS7m3iRVjly0= X-Received: by 2002:a05:660c:209:: with SMTP id y9mr12273766itj.31.1556987816175; Sat, 04 May 2019 09:36:56 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Sat, 4 May 2019 18:36:43 +0200 Message-ID: To: Steven Wade Cc: PHP Internals List Content-Type: multipart/alternative; boundary="000000000000b3ece70588127964" Subject: Re: [PHP-DEV] Proposal for a RFC From: ocramius@gmail.com (Marco Pivetta) --000000000000b3ece70588127964 Content-Type: text/plain; charset="UTF-8" Hi Steven, As it currently stands, the array cast is the only operation capable of exposing object state without triggering any kind of access guards: it is very much required for anything that works with reflection and typed properties, and possibly the only operation in PHP that operates on state without some contraption intercepting its execution. It is also necessary to distinguish dynamic properties from declared object state. For comparison, all of the following have side-effects due to the complexity of the language: * isset() * unset() * property read * property write * ReflectionProperty#getValue() * ReflectionProperty#setValue() Overall, this is problematic, and introduces more magic that I'd gladly avoid, in an endpoint used to work around all the engine magic (the only stable one so far). From my end, this sounds like a bad idea, because it removes one of the very very few referentially transparent guarantees (if not the only one, when dealing with objects) from the language. Greets, Marco On Sat, 4 May 2019, 16:58 Steven Wade, wrote: > Hi Internals team! > > I have an idea for a feature that I'd love to see in the language one day > and wanted to run the idea by you all. > > The idea is to add a new magic method "__toArray()" that would allow a > developer to specifiy how a class is cast to an array. The idea is the same > mentality of __toString(), but, for arrays. > > I would personally love this feature and those I've run it by were also > excited by the idea. So I'm soliciting feedback in hopes that things go > well and I can officially write the RFC. As for implementation, Sara > Golemon is awesome and while chatting a few months back, knocked out a > proof-of-concept implementation < > https://github.com/sgolemon/php-src/tree/experimental.toarray>. There's > still work to be done if this proposal gets to the RFC phase, but again, > just gauging interest here. > > I appreciate any feedback you all can provide. > > Thanks, > > - Steven Wade --000000000000b3ece70588127964--