php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #70236 $->var as syntactic sugar for $this->var
Submitted: 2015-08-11 08:18 UTC Modified: 2016-03-26 21:44 UTC
Votes:26
Avg. Score:2.9 ± 1.6
Reproduced:11 of 16 (68.8%)
Same Version:7 (63.6%)
Same OS:7 (63.6%)
From: z4k4ri4 at gmail dot com Assigned:
Status: Suspended Package: Scripting Engine problem
PHP Version: 7.0.0beta3 OS: All
Private report: No CVE-ID: None
 [2015-08-11 08:18 UTC] z4k4ri4 at gmail dot com
Description:
------------
In a everyday PHP OOP coding, $this->var or $this->method() is so common and verbose, it becomes a distraction for code reading.

I request that PHP add short form of $->var or $->method() as an alias for $this->var and $this->method().


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2015-08-11 17:30 UTC] stas@php.net
-Package: PHP Language Specification +Package: Scripting Engine problem
 [2015-08-26 11:33 UTC] matt at re-gister dot com
I would appreciate this
 [2015-10-19 22:20 UTC] rahi at atsspec dot co
No offense but I think this is a silly idea.  If you have that many $this->something that it's distracting, then you need to take another look at the code.  Maybe have a method that sets the class properties based on an array keyed by the class property names (for example).

For 'setter' type methods you can 'return $this' (fluent interface) to make your code less verbose.
 [2015-12-22 11:38 UTC] daniel dot korner at tu-dortmund dot de
I don't think introducing yet another alias is a good idea. Each new alias only adds unnecessary complexity to the interpreter and to the written PHP code without adding any kind of feature.

But I also think, changing the current "this"-Syntax might be a good idea. Currently the $-Symbol implies that "$this" is a "normal" variable (which it is not!). But the proposed alias "$" would not have this "problem", as the $-Symbol alone isn't a valid variable name.

therefor I think adding this alias with the future plan of removing "$this" might not be such a bad idea.
 [2016-03-26 21:44 UTC] krakjoe@php.net
-Status: Open +Status: Suspended
 [2016-03-26 21:44 UTC] krakjoe@php.net
For this kind of change, an RFC is required.

Please see: https://wiki.php.net/rfc/howto
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Wed Dec 04 18:01:31 2024 UTC