Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:61040 Return-Path: Mailing-List: contact internals-help@lists.php.net; run by ezmlm Delivered-To: mailing list internals@lists.php.net Received: (qmail 74164 invoked from network); 29 Jun 2012 14:25:47 -0000 Received: from unknown (HELO lists.php.net) (127.0.0.1) by localhost with SMTP; 29 Jun 2012 14:25:47 -0000 Authentication-Results: pb1.pair.com header.from=amaury.bouchard@gmail.com; sender-id=pass Authentication-Results: pb1.pair.com smtp.mail=amaury.bouchard@gmail.com; spf=pass; sender-id=pass Received-SPF: pass (pb1.pair.com: domain gmail.com designates 209.85.213.170 as permitted sender) X-PHP-List-Original-Sender: amaury.bouchard@gmail.com X-Host-Fingerprint: 209.85.213.170 mail-yx0-f170.google.com Received: from [209.85.213.170] ([209.85.213.170:59139] helo=mail-yx0-f170.google.com) by pb1.pair.com (ecelerity 2.1.1.9-wez r(12769M)) with ESMTP id A4/13-62543-AEABDEF4 for ; Fri, 29 Jun 2012 10:25:47 -0400 Received: by yenl12 with SMTP id l12so3233367yen.29 for ; Fri, 29 Jun 2012 07:25:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:from:date:x-google-sender-auth:message-id :subject:to:content-type; bh=4qWeLF9N0Tdw4z31NMwu+o2skzDOoNIyXRJa/G/8Xns=; b=nx4WoEMHKh/ti8yTvO3W6INkzVpDq9V+uUN9iOQKOnx3HgJ3r5O6JKJNPfjKY1/C/A vu85ZzF12qExLKGm9iV7r8oOk2HokfNUHufUG4y6cbEqjdqMQkNTd4uTC7rmkhnuSf4+ EgDLnpegrgRtsolRr5PkLodNMLQsZxG6RSgdU6U3lq25zLJzMl4MikbVsB4xWQgLoMXO tgsDTY0XhJzCz3SLQwAdDPJRwb/dSwJrVhgN0IcoiN1snPjwcW2Fousn8bfmGqia4XeJ tzdx2Gk8lcrdO+fN5GlRMfWDEfwNGFKVqReGeI1jfEn6ORfnmUTytmZRcgty7hoy8cj4 M8Ig== Received: by 10.68.204.129 with SMTP id ky1mr7322543pbc.32.1340979944165; Fri, 29 Jun 2012 07:25:44 -0700 (PDT) MIME-Version: 1.0 Sender: amaury.bouchard@gmail.com Received: by 10.68.74.201 with HTTP; Fri, 29 Jun 2012 07:25:23 -0700 (PDT) Date: Fri, 29 Jun 2012 16:25:23 +0200 X-Google-Sender-Auth: kagl1j6ZyXGcpbxmgj7KWYBjpVk Message-ID: To: internals@lists.php.net Content-Type: multipart/alternative; boundary=047d7b2e4cde39106e04c39d3970 Subject: RFC proposal - Syntactic sugar for cloning From: amaury@amaury.net (Amaury Bouchard) --047d7b2e4cde39106e04c39d3970 Content-Type: text/plain; charset=ISO-8859-1 Hello everybody, It's the first time I write on the internals mailing-list, so let me introduce myself quickly. I'm a french and canadian CTO, working in Paris. I lead some PHP projects (mainly the Temma framework and FineFS data replication system). I begin to learn PHP's internal engine, backed by Pierrick Charron. I would like to do an RFC proposal (see below for the associated patch). I was thinking about "what if PHP was a full-object language?". Like, for example, how will we write the simplest code, assuming that objects are handled using pointers since PHP 5. Take a look at this code: $a = 3; $b = $a; $a++; $b still contains the value 3. Now, if we imagine that even the integer data type is managed in an object, the same code will produce two pointers to the same object. Thus, $b will have the value 4, as $a. So, in this imaginary world, we would need to do a lot of object cloning. I wondered how this could be less painful, and I thought about the Pascal language's affectation operator (:=). Then we would be able to write something like that: $a = 3; $b := $a; $c = $a; $a++; $a equals 4, as $c. But $b equals 3. Back in the real world, we are not cloning objects very often. But, like many other syntactic sugars (as the short array syntax), I think it could be handy in some circumstances. There is a patch for this evolution, written by Pierrick. Full source code: https://github.com/adoy/php-src/tree/amaury-clone Code diff: https://github.com/adoy/php-src/commit/5107c0355c50381c7e67230cdc9f563eb3936a15 I'm looking forward to your advices. Cheers! Amaury --047d7b2e4cde39106e04c39d3970--