Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:67853 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 93239 invoked from network); 26 Jun 2013 10:51:29 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 26 Jun 2013 10:51:29 -0000 Authentication-Results: pb1.pair.com smtp.mail=rquadling@gmail.com; spf=pass; sender-id=pass Authentication-Results: pb1.pair.com header.from=rquadling@gmail.com; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.223.170 as permitted sender) X-PHP-List-Original-Sender: rquadling@gmail.com X-Host-Fingerprint: 209.85.223.170 mail-ie0-f170.google.com Received: from [209.85.223.170] ([209.85.223.170:54320] helo=mail-ie0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id 6C/B1-18025-1B7CAC15 for ; Wed, 26 Jun 2013 06:51:29 -0400 Received: by mail-ie0-f170.google.com with SMTP id e11so30943543iej.15 for ; Wed, 26 Jun 2013 03:51:26 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:reply-to:in-reply-to:references:from:date:message-id :subject:to:cc:content-type; bh=+zVD4IW+JkRp1GVu6TFSOdwEJPT/T/NbnqcGLMN20hs=; b=glMQl8ZTKWFaumu2tuvEjUO9ADJCqJYh9ZoK2h9N33JFFZCzAwqVT9jbWFlaYrvEJN /nLLMes+8vjRBvcCbvjpcse/8MVIq5n+BddsYQAhE1c4Xx+0vdSDMBqFeyBuehjhY5Cd O28lo/QCDCzYP1wjGAX0oqO/Kq9DHp1Deh78eCImSUKN0dK4I4kvaoe2KYtuU7awmOEG nWUdp+4UcoH54i0WkS1v9z/0A/eZFg837IuestkP3HUZehbL59s30b3GU5RNoSjJMZr9 Qui9FRkNat3efdLVtWSWtqcC5zBQYWXqhMGumiRosUYPIMlgWy9zbZdJzvdIraoYzgmp /evw== X-Received: by 10.50.16.76 with SMTP id e12mr2155992igd.47.1372243886498; Wed, 26 Jun 2013 03:51:26 -0700 (PDT) MIME-Version: 1.0 Received: by 10.64.23.5 with HTTP; Wed, 26 Jun 2013 03:51:06 -0700 (PDT) Reply-To: RQuadling@GMail.com In-Reply-To: References: Date: Wed, 26 Jun 2013 11:51:06 +0100 Message-ID: To: Tom Oram Cc: PHP internals Content-Type: multipart/alternative; boundary=047d7bdc15d66672d004e00c6d2b Subject: Re: [PHP-DEV] RFC Proposal: New assign value operator From: rquadling@gmail.com (Richard Quadling) --047d7bdc15d66672d004e00c6d2b Content-Type: text/plain; charset=UTF-8 On 25 June 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 > Hi. I'm not going to comment on the merits as such, but I'd be interested in knowing what problem this RFC would solve? Considering PHP has type juggling scalars, it would SEEM (I may have missed the point) that this could result in data loss when the enforced conversion results in 0/False/"". $num = 8; $num := "data from user"; // 0 Unless that is the expected behaviour. Where would this RFC change be used? And having said all of that, I'm not against it, just want to see what it would be useful for that isn't already part of PHP's toolbox. -- Richard Quadling Twitter : @RQuadling EE : http://e-e.com/M_248814.html Zend : http://bit.ly/9O8vFY --047d7bdc15d66672d004e00c6d2b--