Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:70437 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 43477 invoked from network); 27 Nov 2013 09:36:56 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 27 Nov 2013 09:36:56 -0000 Authentication-Results: pb1.pair.com smtp.mail=tom@sclinternet.co.uk; spf=permerror; sender-id=unknown Authentication-Results: pb1.pair.com header.from=tom@sclinternet.co.uk; sender-id=unknown Received-SPF: error (pb1.pair.com: domain sclinternet.co.uk from 209.85.220.179 cause and error) X-PHP-List-Original-Sender: tom@sclinternet.co.uk X-Host-Fingerprint: 209.85.220.179 mail-vc0-f179.google.com Received: from [209.85.220.179] ([209.85.220.179:39162] helo=mail-vc0-f179.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 53/F2-24795-63DB5925 for ; Wed, 27 Nov 2013 04:36:55 -0500 Received: by mail-vc0-f179.google.com with SMTP id ie18so4800780vcb.10 for ; Wed, 27 Nov 2013 01:36:52 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:sender:in-reply-to:references:date :message-id:subject:from:to:content-type; bh=n80XI5kynQITBCnkyFFkIk1SnZE3JXtREjf/dMQdeDQ=; b=TpAP9PiUR76MliFciqy1190mMSSy/zIsoMes1AFjpiqK9bp1+87YPdy2Wz9NaDwZmm mGhLzeBLORYqCCrzZu8pI4dlssIToAzrftgZ7+gwEr8DLGa27pLFqGTRsbGzkO5J/3YN uFC7JwWARGB0sHVE1Y4nZifOaQjnBEbbQmrJC/F7IPbnkj1/TUmxL9xSfsR0IEpTuDeg HygL+6eM1djwZvhOyW51oSSYWVyB72L12UXBmioEdg7H1QRzvDwXqUUPGNEE4LVXeSNJ IVxnZXv7UABEMsIHoOfzc5fOPRbnYuF474nhivSvQ4rLFTM8ai3hmBx8DZkM8gmEuKTg U9rg== X-Gm-Message-State: ALoCoQkwUmIoC0euhOatiYi/87ZrXUqol53s4AUaGd8lmecKnJtPDWl+iM0oRt9VnckMdF2lPqqO MIME-Version: 1.0 X-Received: by 10.52.188.4 with SMTP id fw4mr121074vdc.67.1385545012521; Wed, 27 Nov 2013 01:36:52 -0800 (PST) Sender: tom@sclinternet.co.uk Received: by 10.52.157.135 with HTTP; Wed, 27 Nov 2013 01:36:52 -0800 (PST) Received: by 10.52.157.135 with HTTP; Wed, 27 Nov 2013 01:36:52 -0800 (PST) In-Reply-To: References: Date: Wed, 27 Nov 2013 09:36:52 +0000 X-Google-Sender-Auth: VRDvAm_cajnRnvya-bhTDEJ1DNY Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary=bcaec547cd294ac86504ec25560c Subject: Re: RFC Proposal: New assign value operator From: tom@scl.co.uk (Tom Oram) --bcaec547cd294ac86504ec25560c Content-Type: text/plain; charset=ISO-8859-1 Hi everyone, I let this go before after getting a lot of friction to the idea but the more I think about the more I think it would be really useful. Since writing the original message I've been looking at golang and found that they have a := operation to infer type which is very similar to what I proposed. I'd like to try and start some discussion about this again as I think it would be very useful and really open up the possibility of having objects for primitive types. I shall try and think up some examples to show where I think this could be really useful and follow up this message with that shortly. Best regards to all, TOM On 25 Jun 2013 11:01, "Tom Oram" wrote: > Hi everyone, > > I've got an idea for an RFC proposal and from reading the instructions it > looks like I should run it past you guys first. > > I have not made any contributions to PHP before although I have made some > custom modifications in house in the past and while I'm no longer familiar > with the PHP code base I am confident I have the skills to implement this > should it be accepted. > > What I want to propose is a new assignment operator which rather than > setting the variable to completely new value it would update the value > while maintaining the type. > > The main motivation for this is for easy assignment to value objects aka > assignment operator overloading via a magic method (prehaps called > __assign). > > Here is an example ( for now I will use the PASCAL style assignment > operator := as the new operator as it is a know assignment operator and > currently not used in PHP): > > // For a class defined like so... > class MoneyValue > { > protected $amount; > > public function __assign($value) > { > $this->amount = $value; > } > } > > // The amount could then be assigned using the new operator like this > > $price = new MoneyValue(); > > $price := 29.99; > > While the primary focus would be for assignment operator overloading as I > just displayed in the previous example, for consistency it could be used > with scalar values to preserve type like so: > > // $str is now a string > > $str = 'Original String'; > > // Using the new assignment variable would cast the value being assigned > to the variable's type > // (in this case a string). So > > $str := 7; > > // Would be the equivalent to > // > // $str = (string) 7; > // > // $str === "7" > > > Another quick example: > > $num = 5; > > $num := '12'; > > // Equivalent to > // > // $num = (int) '12'; > // > // $num === 12; > > So what do you guys think? > > If I get a good response I'll look into how to create a proper RFC and > start trying to work out how to implement it. > > Many thanks and look forward to some responses, > Tom > > > -- > **************************************************** > PLEASE NOTE: For support requests please > use support@scl.co.uk instead of emailing > staff directly, this way your request is likely to > be dealt with more efficiently. > **************************************************** > Tom Oram - SCL Internet Services > PO Box 8, Cardigan, Ceredigion, SA41 3YA > Website: http://www.scl.co.uk/ > Tel: +44 (0) 1239 622 411 > Fax: +44 (0) 1239 622428 > Company Reg. No. 2441708 > **************************************************** > --bcaec547cd294ac86504ec25560c--