Skip to content

Instantly share code, notes, and snippets.

@ShawnMcCool
Last active August 29, 2015 14:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ShawnMcCool/4253430ceaebb9bce815 to your computer and use it in GitHub Desktop.
Save ShawnMcCool/4253430ceaebb9bce815 to your computer and use it in GitHub Desktop.
PHP RFC: Instance Reference Sugar 0.2
====== PHP RFC: Instance Reference Sugar ======
* Version: 0.2
* Date: 2015-03-09
* Author: Shawn McCool, shawn@heybigname.com
* 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.
@martindilling
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment