php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #66832 Feature: Reverse assignment string operators
Submitted: 2014-03-06 09:50 UTC Modified: 2014-03-06 11:55 UTC
Votes:1
Avg. Score:4.0 ± 0.0
Reproduced:1 of 1 (100.0%)
Same Version:1 (100.0%)
Same OS:1 (100.0%)
From: nicolas dot giraud dot dev at gmail dot com Assigned:
Status: Wont fix Package: Strings related
PHP Version: Irrelevant OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please — but make sure to vote on the bug!
Your email address:
MUST BE VALID
Solve the problem:
44 - 20 = ?
Subscribe to this entry?

 
 [2014-03-06 09:50 UTC] nicolas dot giraud dot dev at gmail dot com
Description:
------------
This is not a bug but a feature request. I thought someone already asked it but I wasn't able to find anything like that. 
I would like to know if it's possible to have reversed assignment string operator.
Thank you


Test script:
---------------
$a =. $b; // same as $a = $b . $a;

Expected result:
----------------
$a = 'World';
$b = 'Hello ';
$a =. $b; //$a worth now "Hello World";

//Multiple string operations in assignements
$a = 'a'; $b = 'b'; $c = 'c';
$c .= $b .= $a; //$c worth now 'cba'

$a = 'a'; $b = 'b'; $c = 'c';
$c =. $b =. $a; //$c worth now 'abc'

Actual result:
--------------
Not implemented (yet?)
Only the following snippet works:

$a = 'a'; $b = 'b'; $c = 'c';
$c .= $b .= $a; //$c worth now 'cba'

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2014-03-06 11:55 UTC] nikic@php.net
-Status: Open +Status: Wont fix
 [2014-03-06 11:55 UTC] nikic@php.net
This is too exotic. No language that I am aware of supports postfix compound assignment operators. The use cases are rather limited and it has a lot of potential of confusing and typos, as it's so close to the normal compound assignment syntax.

Furthermore we'd have to add this for all other operators as well, to stay consistent. In which case we'd run into issues like =& already being the by-ref assignment operator.
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 26 19:01:29 2024 UTC