Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:97263 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 91606 invoked from network); 2 Dec 2016 14:56:53 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 2 Dec 2016 14:56:53 -0000 Authentication-Results: pb1.pair.com smtp.mail=bowersbros@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=bowersbros@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 74.125.82.42 as permitted sender) X-PHP-List-Original-Sender: bowersbros@gmail.com X-Host-Fingerprint: 74.125.82.42 mail-wm0-f42.google.com Received: from [74.125.82.42] ([74.125.82.42:38269] helo=mail-wm0-f42.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 9F/7C-01781-4BB81485 for ; Fri, 02 Dec 2016 09:56:53 -0500 Received: by mail-wm0-f42.google.com with SMTP id f82so18034554wmf.1 for ; Fri, 02 Dec 2016 06:56:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=K5IuxdzAtAki5G9i+dxCPdtmgf3TT9WnCdC6+8On4aE=; b=S4IxUagUirM5cfQNs0M6rD6mXNs0EekrNyr41VBYXdz1uAvb4XaCh96u6Zas6WjXBO EfhSTDExd7UrLqrDmQJOmmLqVJUzltJuP9yRJOtYSAJqljBcSubuk/i72f0P98O3gaJ0 1PAyQDiuYh5hRz8Q+kBfYE/+Jrl3rfFupRAZjgku0wyTXwWPewcKlP+D8e/AbIpvOdvj 57J9JuIfQtU6mwfxhUm5Tf+aQ5jLrD/87bgI+0O0U/0LCKK5LWSvXS4+e7GQSVMiQDPD 6y0EHBDmRT4L6+Pn5iVwQ7/S8gV88WJc+Vg3DaS8BTW/OED6OH8jCOi7rL2oqMlwh8k4 pU9w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=K5IuxdzAtAki5G9i+dxCPdtmgf3TT9WnCdC6+8On4aE=; b=Cckgze/LBL8FqMznTAndpAaiVb2Z8TCNFdc5K7ksauHU8MXs4D5XNrYAQACbUbrDOg kEa1j2JnMahE4/rsfajyF/OwHY+htmcYgkjtYNNmnv3Af9KqOzDWE+vH2o0CVACqyUE6 EJKReIqHygP04Bibk3UtlcLmg2qOsGNMdjRJONcbDZymA+XTzfcTmoT/MFO08y/YbWvm 4ELyE4hHtlanRHseBMdbZKUIdz5VGmqOMlrwk1bBB55MXUj5DKs9kAghUxpEUEoywHLW Femx19W8acM9Y+0MUckwLj0/X7Ucf0keo7VE0EvaFo95sXB6JgaSSCHTiArzyYrIbgbb FEUQ== X-Gm-Message-State: AKaTC03eEyCYR1TmuQedy4olaZkRVZR3rhyX26i8GaAzNi/bkS9gRScrl0Rvj3hOjYPTQYbZBAPzTowub8UAyQ== X-Received: by 10.28.137.193 with SMTP id l184mr3174629wmd.88.1480690609889; Fri, 02 Dec 2016 06:56:49 -0800 (PST) MIME-Version: 1.0 Received: by 10.28.232.77 with HTTP; Fri, 2 Dec 2016 06:56:49 -0800 (PST) In-Reply-To: References: Date: Fri, 2 Dec 2016 14:56:49 +0000 Message-ID: To: PHP Content-Type: multipart/alternative; boundary=001a11441764d3365f0542ae25db Subject: Fwd: [PHP-DEV] Re: [Concept] Magic Casting From: bowersbros@gmail.com (Alex Bowers) --001a11441764d3365f0542ae25db Content-Type: text/plain; charset=UTF-8 Sorry for forward. Hit reply, not reply-all. ---------- Forwarded message ---------- From: Alex Bowers Date: 2 December 2016 at 14:31 Subject: Re: [PHP-DEV] Re: [Concept] Magic Casting To: David Rodrigues Another benefit this would give frameworks / user land code is the ability to mock / simulate having scalar object types. For instance, A class called `Str` could be used to cast all "string" inputs to its type, and then everywhere in the framework / user land code, based on __cast() it could cast them all to a Str instance, and be used with methods on. This will allow $string->toUpperCase() to be possible etc, whilst acting on a plain string. On 2 December 2016 at 14:30, Alex Bowers wrote: > To me, in pseudo logic it would work as so: > > Currently it does this: > > A method with the signature of function_name(Collection $collection) has > been called. The parameter I have is of type Collection. Let it continue; > or alternatively, the parameter is not of type Collection, throw the error. > > The new method will be: > > A method with the signature of function_name(Collection $collection) has > been called. The parameter I have is of type collection. let it continue. > > Alternatively, > The parameter is not of type collection, does Collection implement a > __cast() magic method. If it does, Pass the parameter into that __cast() > method. If the response is an instance of Collection, let it through. If it > is not, throw the error. > > As to how this would be implemented, r how the engine is built. This is > not something I am aware of really. I will be willing to learn, and assist > somebody / get assistance in the building of this feature, but it would > take me a lot longer than it would take a real core member to do. > > But effectively, it will call Type::__cast() > --001a11441764d3365f0542ae25db--