Last active
August 29, 2015 14:16
-
-
Save ShawnMcCool/4253430ceaebb9bce815 to your computer and use it in GitHub Desktop.
PHP RFC: Instance Reference Sugar 0.2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
====== PHP RFC: Instance Reference Sugar ====== | |
* Version: 0.2 | |
* Date: 2015-03-09 | |
* Author: Shawn McCool, [email protected] | |
* Status: In Discussion | |
===== Summary ===== | |
In order to access instance variables and methods, one must use the `$this->` prefix. | |
The problem with this is that it reduces expressiveness in the language and increases the amount of unnecessary decoration, reducing readability. | |
This RFC proposes a single character syntax sugar form of `$this->`. Instead, an `@` can be used to reference instance variables and methods. | |
The @ replaces the normal $ variable prefix. | |
===== Example ===== | |
<file php Addition.php> | |
<?php | |
class Addition { | |
private $number | |
public function __construct($number) { | |
@number = $number; | |
} | |
public function original() { | |
return @number; | |
} | |
public function addTo($amount) { | |
return @add(@number, $amount); | |
} | |
private function add($one, $two) { | |
return $one + $two; | |
} | |
} | |
</file> | |
===== Implementation ===== | |
@ is basically a macro that expands to `$this->` | |
===== Backwards Compatibility ===== | |
Leave `$this->` available. | |
@ is currently used for error suppression. This error suppression format should be removed in favor of error exceptions. | |
===== Proposed PHP Version(s) ===== | |
This is proposed for the next PHP x, currently PHP 7. |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Is there any news on this? ;)
Would really like to see this implemented at some point.
Not sure I have any preference on the character used, just something shorter than
$this->
xD