Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:105906 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 88353 invoked from network); 13 Jun 2019 17:10:00 -0000 Received: from unknown (HELO mail-yb1-f170.google.com) (209.85.219.170) by pb1.pair.com with SMTP; 13 Jun 2019 17:10:00 -0000 Received: by mail-yb1-f170.google.com with SMTP id y17so593670ybm.6 for ; Thu, 13 Jun 2019 07:23:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=P1E5PMGUKN6H5G8MU5YiwW8bnPhh/2WVh5nvmIyMSIk=; b=VJkdqo3uZb3rfFViESMXBaldSSo/KT27/bau1hidEX5i5Chua7WXVJfphyzxmDVUVA lOA4bKDSnUG3sjB+eT0IMuyQMh83LNGP3yW3sRY8WExeAnNyNy5B4jnH4sNDkx8pW/Re Vjv8Jmm6rJJVf4w6snY+UIqP1NPWgW9az5b8dEOsS3bXrdKtefTpJsfE1gZpCEHxkbHv TA8vn+PerF/CwV58pUaVi/VR/D4O2EBRR/PRBvpkCUtjgVyZwl8YHoQkYmuRzWs3c7Pq tCLTfX+n8n6/U0I8QsDzFiZ+9DQlUwNqxTLPB/47KFoi5ahQbYDfB7vlNa2+ahtID8Sm pUSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=P1E5PMGUKN6H5G8MU5YiwW8bnPhh/2WVh5nvmIyMSIk=; b=BEoas4/vgVBna9+R68GjygooE3TzrFNZ/bVMDRLyx8msXsqgfpFyBLJjLgS2rX3KvI wLGjNnE78VIGX36l2eLAEwHxQD/JN0ZcIq6zB3NPDQp6lqCbIXayTKmvK8GLCDY4MkBG EMLqnNjPyVFiRZRhs8mu6P7COTEqEVQlWmCk3Ps2XqW0tHXYm08hdwmNb/I3mWD0+v88 89aPrcd3bhUeTHkhF8DrpOWCU0BEiAhX9nLaMg/VU96LqB9g3q7g3QIrV1X/eOyVgCKM GU8OtZkPcuTutNSkEXoE0vVy+ktqL1FtFMopp9xAn/OznfkT4CP2ETgxXOJzbzuIcIko og3w== X-Gm-Message-State: APjAAAVtBCI3NcnWlsawKd5FHorJ1uSP/AzpZ0PXrAyQCliypPnHsoht yFNFg42QrYuG2cqUxsvpDFg= X-Google-Smtp-Source: APXvYqwvtaCir0nL/vuDHAs8cjGD245bIKiSzDZVpHfjuu2ur1pxRwqrfVKegU2NaGN0RGeXbfb7zw== X-Received: by 2002:a25:7496:: with SMTP id p144mr41653415ybc.507.1560435789571; Thu, 13 Jun 2019 07:23:09 -0700 (PDT) Received: from [172.20.10.2] (mobile-166-177-184-230.mycingular.net. [166.177.184.230]) by smtp.gmail.com with ESMTPSA id b63sm37392ywb.12.2019.06.13.07.23.08 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 13 Jun 2019 07:23:09 -0700 (PDT) Content-Type: text/plain; charset=us-ascii Mime-Version: 1.0 (Mac OS X Mail 12.4 \(3445.104.8\)) In-Reply-To: Date: Thu, 13 Jun 2019 10:23:06 -0400 Cc: Internals Content-Transfer-Encoding: quoted-printable Message-ID: <99792856-D21C-4B52-9717-F09705FD614E@gmail.com> References: <1946899E-7EFC-4206-B26D-CD44838315A3@gmail.com> <898DDEB6-4CC3-44F8-8583-BC3AE22C6928@gmail.com> To: Rowan Collins X-Mailer: Apple Mail (2.3445.104.8) Subject: Re: [PHP-DEV] Proposal for a RFC From: stevenwadejr@gmail.com (Steven Wade) Apologies for the super late response: > A recursive method would certainly have more value, because it = actually > does something more than translate one syntax to another. On the other > hand, the use case that comes to mind is serialization, and we already = have > more specific methods and systems for that. How could this new magic method be recursive? If it only works if you = manually declare __toArray() in your class, wouldn't you then as the = user be in charge of casting anything manually in your method = implementation? >=20 > I guess that's what it comes down to, what *specific* use cases would = this > feature be intended to help with? Is there some code of your own that > inspired you to propose it, or something you've seen publically that = would > benefit from it? Originally, it was inspired by seeing Laravel's use of Arrayable as an = interface and if something implements that, calling that class' = `toArray()` method, and wishing that was built in so that frameworks = didn't re-invent the wheel every time.=20 As far as in my code, collections being cast as an array easily would be = nice. Models with relationships, being able to implement that cast and = control how your model and its children are (or aren't) represented. = That's useful for returning an array in a controller for an API, or for = simply adding context to a log message. IMO, the point is, it's another tool in the developers arsenal that they = can use when they see fit. Not everyone will use it and not everyone = will see the benefit of it, and that's ok, but for those that would and = could, __toArray() is for them (and me). -- Steven Wade stevenwadejr@gmail.com