痛风什么东西不可以吃| 三八妇女节送老婆什么礼物好| 十二月二十三是什么星座| 金牛座和什么座最配| 测智力去医院挂什么科| 抗体阳性说明什么| dna是什么意思| 肝化灶是什么意思| 脂溢性脱发用什么洗发水| 美国的国花是什么花| 车顶放饮料是什么意思| 西瓜汁加什么好喝| 湖南有什么景点| 小燕子吃什么| 小孩风热感冒吃什么药| 淼是什么意思| 胎盘下缘达宫颈内口是什么意思| 脸热发红是什么原因| 6月13日是什么星座| 胎儿胆囊偏小有什么影响| 家是什么| 流鼻血去药店买什么药| 头发需要什么营养| 什么为力| 肠胃炎可以吃什么| 先祖是什么意思| 病假需要什么医院证明| 淋巴细胞计数偏高是什么原因| 灰指甲用什么药最好| 生猴子是什么意思| 男朋友有什么用| 来大姨妈吃什么好| 球蛋白的功效与作用是什么| 什么是甲亢| 拉痢疾是什么症状| 除皱针什么牌子效果最好| 中蛊的人有什么症状| 与虎谋皮什么意思| 吃什么受孕率又快又高| 维生素a中毒是什么症状| 穷极一生是什么意思| 知柏地黄丸主治什么| 缺如是什么意思| 麻豆是什么意思| 吹泡泡什么意思| 容易出汗是什么问题| 什么的温度| 君子兰什么时候开花| 咖啡有什么作用| 鸡精和味精有什么区别| 乘载和核载是什么意思| 贤淑是什么意思| 烟卡是什么| 赘婿是什么意思| 喝酒对身体有什么影响| 抽筋缺什么维生素| 蜂蜜吃有什么好处| 10015是什么电话| 一直干呕是什么原因| 阿咖酚散是什么| 红曲红是什么| 戊五行属什么| 黄体不足吃什么药| 大叔是什么意思| 氧化钙是什么| 末那识是什么意思| 目翳是什么意思| hcy是什么检查项目| 什么叫因果| 婴儿眼屎多是什么原因| ph值是什么意思| 焦虑症吃什么中成药| 康熙叫什么名字| 喜上眉梢是什么意思| 喉咙痛挂什么科| 屈光不正什么意思| 脂溢性脱发用什么洗发水| 什么是热射病| 坤沙酒是什么意思| 牙痛用什么药| 丁火命是什么意思| 抗心磷脂抗体是什么| 鼠五行属什么| 712什么星座| 什么是简历| 什么是事业编| 咖啡伴侣是什么东西| 痔疮有什么特效药| 蝙蝠进屋有什么预兆| 吃什么白细胞升的最快| 病毒感染有什么症状| 脱肛是什么原因造成的| hpv感染是什么意思| hsil是什么意思| 翠玉是什么玉| 下水道井盖为什么是圆的| 男人湿气重吃什么药| 大生化是检查什么| 吃什么补肝最好| 矽肺是什么意思| mic是什么单位| 什么品牌蓝牙耳机好| 荨麻疹忌口什么食物| 月经期可以吃什么水果| 剑客是什么意思| hct是什么| 噬是什么意思| 卖什么小吃简单挣钱| 体毛多是什么原因| 脾虚吃什么食物补最快| 五官是什么| 过敏性鼻炎吃什么水果好| 防风通圣颗粒治什么病| 来月经拉肚子是什么原因| 人生最重要的是什么| 尿检蛋白质弱阳性是什么意思| 血糖高吃什么水果好| 高三学生吃什么补脑抗疲劳| 阴虚内热吃什么药| 麻雀吃什么| 桃花是什么颜色| 什么是手机号| 50岁眼睛模糊吃什么好| 老赖是什么意思| 眼胀是什么原因| 海丽汉森是什么档次| 什么的黎明| 心梗是什么原因引起的| rue是什么意思| 黑蝴蝶代表什么| 阴囊潮湿是什么原因| 幽门螺杆菌是什么| mrt是什么意思| 平纹布是什么面料| 颐养天年是什么意思| 荥在中医读什么| 心口下面疼是什么原因| 润喉咙什么东西最合适| 祎是什么意思| 机警是什么意思| 山青读什么| 罗汉果泡水有什么好处| 梦见明星是什么预兆| 花椒有什么功效与作用| 乙肝五项第二项阳性是什么意思| 以身相许什么意思| 来大姨妈喝红糖水有什么作用| 警察两杠一星是什么级别| 自缚是什么意思| 卵圆孔未闭是什么意思| UFS是什么意思| 性侵是什么意思| 麻风疫苗什么时候打| ca125是什么意思| 面目狰狞是什么意思| 郭富城属什么生肖| 弥可保是什么药| 临幸是什么意思| 做核磁共振挂什么科| 属牛的跟什么属相最配| 腋下有异味是什么原因| 每天经常放屁什么原因| 记仇的人是什么性格| 瞌睡是什么意思| 为什么会得霉菌性阴道炎| 铜绿假单胞菌用什么抗生素| 土豆炒什么好吃| 打冷是什么意思| 小孩晚上睡觉出汗是什么原因| 小手指麻木是什么原因| 抗核抗体阳性是什么意思| 蜈蚣泡酒有什么功效| 一九六八年属什么生肖| 智商是什么意思| 李逵属什么生肖| 车前草长什么样| 孕期心情不好对胎儿有什么影响| 缓释片是什么意思| 失物招领是什么意思| 出挑是什么意思| 月经结束一周后又出血是什么原因| 水解奶粉是什么意思| 铁皮石斛可以治什么病| 夏天流鼻血是什么原因| 什么叫人| 嚣张是什么意思| 五月二十九是什么星座| 木甚念什么| 做梦手机坏了什么预兆| 睡眠不好是什么原因| 尿频尿急尿痛吃什么药| 悠闲惬意什么意思| 天津市市长是什么级别| 双花红棍是什么意思| 补肾吃什么药好| 茶叶蛋用什么茶叶最好| 蛋白质是什么食物| 根管预备是什么意思| 故宫为什么叫故宫| nnd什么意思| 玄冥是什么意思| 怀孕脉象是什么样子| 谷草谷丙高是什么原因| 什么叫同型半胱氨酸| 喝什么解暑| 老是想拉尿是什么原因| 上颚疼痛吃什么药| 身份证前六位代表什么| 上发条是什么意思| 察言观色是什么意思| 慌张的反义词是什么| 薄荷泡水喝有什么功效| 婉甸女装属于什么档次| 喜上眉梢是什么意思| 李连杰什么病| 乌龟浮水是什么原因| 准备要孩子需要注意什么| cnd是什么意思| 梦见屎是什么预兆| 请多指教是什么意思| 河南专升本考什么| 书中自有颜如玉是什么意思| 满月脸水牛背是什么病| 蚕屎做枕头有什么好处| 257什么意思| 11月27日是什么星座| 8月2号是什么星座| 土耳其是什么人种| 兆后面的单位是什么| 过敏性皮肤用什么护肤品比较好| 看睾丸去医院挂什么科| 美国为什么不打朝鲜| 摸不到心跳是什么情况| 第二学士学位是什么意思| 朱允炆为什么不杀朱棣| 吃什么容易胖| 25度穿什么衣服| 人次什么意思| 舌苔厚黄吃什么药| 什么的油菜花| 什么水果是降火的| 西游记有什么故事| 7月22日是什么星座| 什么是公因数| 21金维他什么时候吃效果最好| 女性长期缺维d会带来什么病| 猫的胡须有什么作用| 牙齿痛吃什么| 水土不服是什么意思| 罗汉肉是什么肉| mbc是什么意思| 什么情况下需要根管治疗| 早饭吃什么| pdc是什么意思| 肝功能八项检查什么| 虾青素有什么功效| 蜜獾为什么什么都不怕| 丁克是什么| 50至60岁吃什么钙片好| 爱叶有什么作用和功效| 幼字五行属什么| 卡替治疗是什么意思| 什么是僵尸肉| 金今念什么| 百度
rfc:this_var

《财经》杂志社记者王晓璐涉嫌编造并传播虚假

Introduction

百度 做好人好事的杰出青年,帮卖扇老妪题字,引人抢购。

Historically PHP implementation accessed special $this variable using two different methods. In some cases this might lead to significant inconsistency, when $this accessed through different methods might have different values.

class C {
  function foo() {
    var_dump($this);
  }
  function bar() {
    $a="this";
    $$a=42;
    var_dump($this); // prints int(42)
    $this->foo();    // prints object(C)#1 (0) {}
  }
}
$x = new C;
$x->bar();

This RFC proposes disabling modification of $this variable using “magic code” and make $this always behave in the same way.

Proposal

Disable using $this as parameter

The following code worked in PHP 7, but will emit compilation error in PHP 7.1

function foo($this) { // Fatal error: Cannot use $this as parameter
}

Disable using $this as static variable

The following code leaded to “Cannot re-assign $this” compilation error. In PHP 7.1 it will produce more suitable error message - “Cannot use $this as static variable”.

static $this; // Fatal error: Cannot use $this as static variable

Disable using $this as global variable

The following code worked in PHP 7, but will emit compilation error in PHP 7.1

global $this; // Fatal error: Cannot use $this as global variable

Disable using $this as catch variable

The following code worked in PHP 7, but will emit compilation error in PHP 7.1

try {
  ...
} catch (Exception $this) { // Fatal error: Cannot re-assign $this
}

Disable using $this as foreach value variable

The following code worked in PHP 7, but will emit compilation error in PHP 7.1

foreach ($a as $this) { // Fatal error: Cannot re-assign $this
}

Disable ability to unset() $this

It's not allowed to re-assign $this, so why it should be allowed to unset() it. The following code worked in PHP 7, but will emit compilation error in PHP 7.1

unset($this); // Fatal error: Cannot unset $this

Disable ability to re-assign $this indirectly through $$

An attempt to re-assign $this through $$ assignment will lead to throwing of Error exception.

$a = "this";
$$a = 42; // throw new Error("Cannot re-assign $this")

It's still possible to read $this value through $$.

Disable ability to re-assign $this indirectly through reference

Indirect re-assign $this through reference won't make effect in PHP 7.1

class C {
  function foo(){
    $a =& $this;
    $a = 42;
    var_dump($this); // prints object(C)#1 (0) {}, php-7.0 printed int(42)
  }
}
$x = new C;
$x->foo();

Disable ability to re-assign $this indirectly through extract() and parse_str()

Few internal PHP functions may re-assign local variable. In PHP 7.1 they cannot change value of $this variable and throw Error exception.

class C {
  function foo(){
    extract(["this"=>42]);  // throw new Error("Cannot re-assign $this")
    var_dump($this);
  }
}
$x = new C;
$x->foo();

get_defined_vars() always doesn't show value of variable $this

In PHP 7.0 and below get_defined_vars() might show or not show value of $this depending on some condition. (e.g. it was shown if we used $this variable itself, but not if it was used in a $this property reference or method call). In PHP 7.1 we won't show the value of $this in all cases.

Always show true $this value in magic method __call()

In PHP 7.0 and below $this in static magic method __call() had value NULL. However it was possible to access properties and call object methods.

class C {
  static function __call($name, $args) {
    var_dump($this); // prints object(C)#1 (0) {}, php-7.0 printed NULL
    $this->test();   // prints "ops"
  }
  function test() {
    echo "ops\n"; 
  }
}
$x = new C;
$x->foo();

Using $this when not in object context

Attempt to use $this in plain function or method now will lead to exception “Using $this when not in object context”. This unifies behavior with method call and property access. Previously PHP emitted “undefined variable” notice and continued execution assuming $this is NULL. It's still possible to use isset($this) and empty($this) to check object context.

function foo() {
    var_dump($this); // throws "Using $this when not in object context"
                     // php-7.0 emitted "Undefined variable: this" and printed NULL
}
foo();

Backward Incompatible Changes

All the BC breaks are intentional and they are described in the proposal section.

Proposed PHP Version(s)

PHP 7.1

RFC Impact

To SAPIs

none

To Existing Extensions

none

To Opcache

The proposed implementation is compatible with opcache

Open Issues

none

Proposed Voting Choices

The vote is a straight Yes/No vote, that requires a 2/3 majority. The voting began on Jun 6 and will close on Jun 16.

Fix inconsistent behavior of $this variable?
Real name Yes No
aharvey (aharvey)  
ajf (ajf)  
bishop (bishop)  
bwoebi (bwoebi)  
colinodell (colinodell)  
daverandom (daverandom)  
davey (davey)  
dm (dm)  
dmitry (dmitry)  
dragoonis (dragoonis)  
fa (fa)  
galvao (galvao)  
guilhermeblanco (guilhermeblanco)  
hywan (hywan)  
jpauli (jpauli)  
kguest (kguest)  
krakjoe (krakjoe)  
laruence (laruence)  
lcobucci (lcobucci)  
leigh (leigh)  
levim (levim)  
lstrojny (lstrojny)  
marcio (marcio)  
mariano (mariano)  
mattwil (mattwil)  
mbeccati (mbeccati)  
mrook (mrook)  
nikic (nikic)  
ocramius (ocramius)  
peehaa (peehaa)  
philstu (philstu)  
pierrick (pierrick)  
pollita (pollita)  
rasmus (rasmus)  
sammyk (sammyk)  
sebastian (sebastian)  
sobak (sobak)  
thekid (thekid)  
tpunt (tpunt)  
trowski (trowski)  
yohgaki (yohgaki)  
zeev (zeev)  
zimt (zimt)  
Final result: 43 0
This poll has been closed.

Patches and Tests

Implementation

After the project is implemented, this section should contain

  1. the version(s) it was merged to
  2. a link to the PHP manual entry for the feature
rfc/this_var.txt · Last modified: by 127.0.0.1

?
建字五行属什么 生肖本命带红花是什么生肖 抑郁症吃的药叫什么 在吗是什么意思 逆水行舟什么意思
收缩压是什么 不举什么意思 肝硬化是什么意思 灵五行属性是什么 四川有什么好大学
吃什么提高免疫力最快 医保报销需要什么材料 龙骨是什么动物的骨头 茯苓生长在什么地方 粉玫瑰代表什么
李五行属什么 血液净化是什么意思 来曲唑片是什么药 蛰伏是什么意思 梦见挖土豆是什么意思
阴道炎挂什么科hcv8jop7ns9r.cn 喝酸奶有什么好处hcv9jop3ns9r.cn 什么呼什么应hcv7jop6ns6r.cn 倒睫是什么意思hcv8jop8ns3r.cn 火车动车高铁有什么区别hcv9jop5ns9r.cn
瞽叟是什么意思hcv8jop5ns3r.cn die是什么意思dayuxmw.com 扁桃体结石是什么原因引起的hcv9jop7ns4r.cn 老年痴呆症又叫什么hcv8jop1ns7r.cn lh是什么意思啊bysq.com
黑裙配什么颜色的上衣hcv9jop2ns0r.cn 吃葱有什么好处和坏处hcv9jop0ns0r.cn 打封闭是什么意思hcv8jop4ns5r.cn 素什么意思hcv9jop4ns5r.cn 什么梳子梳头最好hcv8jop9ns5r.cn
总是拉稀大便不成形是什么原因hcv9jop2ns2r.cn 唐僧属什么生肖hcv9jop5ns2r.cn 尿蛋白1十是什么意思hcv7jop9ns7r.cn 喝什么酒不会胖hcv9jop7ns4r.cn 肚子大挂什么科hcv9jop5ns7r.cn
百度