心率低40多吃什么药| 身份证穿什么颜色的衣服| 不来月经吃什么药催经| 尿发红什么原因| 元宝是什么意思| 体重除以身高的平方是什么指数| 8月1日是什么星座| 什么是省控线| 两岁宝宝拉肚子吃什么药| 总感觉饿是什么原因| 方圆脸适合什么发型| 弯弯的月亮像什么| 罗红霉素和红霉素有什么区别| 11月2日什么星座| 王维被称为什么| 男属龙和什么属相最配| 羊后马前对是什么生肖| 太阳是什么颜色的| 羊水为什么叫羊水| 超级碗是什么比赛| 火供是什么意思| 什么是腰肌劳损| 头晕吃什么药| 紧张性头痛吃什么药| 颈动脉斑块挂什么科| 朋字五行属什么| 男孩过生日送什么礼物好| 补办户口本需要什么材料| 古力娜扎全名叫什么| 造纸术什么时候发明的| 脸上白了一小块是什么原因| 抵押什么意思| 为什么手上会起小水泡| ne是什么意思| 尿尿疼是什么原因| 请佛像回家有什么讲究| 百褶裙搭配什么上衣| 奶冻是什么| 废品收入计入什么科目| 绿松石五行属什么| 你的脚步流浪在天涯是什么歌曲| 睾酮素低了有什么症状| 7.20是什么星座| 什么颜色属土| 安徽菜属于什么菜系| 今年农历是什么年| 我追呀追呀是什么歌曲| 红茶加枸杞有什么功效| 黄片是什么| 3月14号是什么星座| 12min是什么意思| 开水烫了用什么紧急处理| 宝宝什么时候开始说话| 大便呈绿色是什么原因| 所言极是是什么意思| 百忙之中什么意思| 控销药品什么意思| 1985年属牛的是什么命| 纳入是什么意思| 什么是社会考生| 亚甲炎是什么病| 什么是主观什么是客观| 番石榴什么时候成熟| 折耳根是什么东西| 恚是什么意思| 从父是什么意思| 艾司唑仑片是什么药| 子宫增厚是什么原因| 金银花为什么叫忍冬| 扁平疣是什么原因引起的| 一月14号是什么星座| 1958年属什么| 38码衣服相当于什么码| 轩尼诗是什么酒| 肚子受凉吃什么药| 梦见抬死人是什么意思| 有龙则灵的灵是什么意思| 睡眠不好用什么药调理| 吃什么排出全身毒素| 拉肚子可以吃什么药| 手麻脚麻是什么原因引起的| 咿呀咿呀哟是什么歌| 任督二脉是什么意思| 猿人头是什么牌子| 迥异是什么意思| 红海为什么叫红海| 最贵的玉是什么玉| 李隆基是李世民的什么人| 姨妈期间可以吃什么水果| 念珠菌感染用什么药效果好| 隔夜茶为什么不能喝| 哺乳期抽烟对宝宝有什么影响| 什么时间吃水果最好| 害怕是什么意思| 赑屃是什么意思| 闹乌龙是什么意思| 独生子女证办理需要什么材料| 取关是什么意思| 口蘑不能和什么一起吃| 胃不好吃什么最养胃| 牛百叶是什么部位| 柬埔寨用什么货币| 芦荟胶有什么用| 偷鸡不成蚀把米什么意思| 封闭抗体是什么意思| zgo手表是什么牌子| eb病毒感染是什么病| 骨挫伤是什么意思| 梦见到处都是蛇预示着什么| 胰腺低密度影什么意思| 卤水是什么水| 屁眼痒是什么原因| 什么产品祛斑效果最好| 肩膀疼去医院挂什么科| 正常白带是什么颜色| 菜花炒什么好吃| 茶艺师是做什么的| 胆固醇高有什么症状| 虎口是什么穴位| 迪士尼是什么意思| 纸尿裤和拉拉裤有什么区别| 2002年是什么命| 电压高是什么原因造成| 怀孕初期分泌物是什么样的| 早上一杯温开水有什么好处| 痛风吃什么药效果好| 天秤女和什么星座最配| 气短气喘吃什么药| 宫颈炎吃什么药最好| 维生素b2是什么| 麻药过敏什么症状| 嗓子痒痒吃什么药| 小孩出冷汗是什么原因| 实蛋是什么| 山药叶子长什么样图片| 6.5号是什么星座| 117是什么电话| 塞肛门的止痛药叫什么| 角鲨烯有什么作用| 理疗和按摩有什么区别| 手发抖是什么原因引起的| 游离甲状腺素偏低是什么意思| 什么是静脉血栓| 胰腺炎是什么症状| aso是什么意思| 什么全什么美| 三九胃泰治什么胃病效果好| 桉是什么意思| 女人最大的底气是什么| 道地是什么意思| 什么叫同工同酬| 狂犬疫苗挂什么科| 生地麦冬汤有什么功效| 一天老是放屁是什么原因| 嘴唇发麻是什么病兆| 王大锤真名叫什么| a2是什么意思| 看破红尘是什么意思| 中国精神是指什么| 鱼条念什么| 出汗有异味是什么原因| 吃榴莲对身体有什么好处| 酸中毒是什么意思| 诺氟沙星胶囊治什么病| 眼睛黄是什么原因| 不可小觑什么意思| 高温丝假发是什么材质| 唐僧肉是什么意思| 下午五点是什么时辰| 11.10是什么星座| 平板有什么用处| 睡觉时身体抽搐是什么原因| 什么叫牙齿根管治疗| 处女男和什么星座最配| 黄芪有什么好处| 便秘吃什么药好| 50年婚姻是什么婚| 175是什么尺码| 银行降息意味着什么| 润滑油是什么| 梦见刮胡子是什么意思| 豹子是什么牌子| 为什么会长口腔溃疡的原因| 乳糖不耐受可以喝什么奶| 市公安局局长是什么级别| 有什么故事| 碎银子是什么茶| 两鬓长白发是什么原因| 怀孕早期需要注意什么| fte是什么意思| 生粉和淀粉有什么区别| 白细胞高什么原因| 走之旁与什么有关| 吃什么雌激素会增多| 立秋当天吃什么| 胸变大是什么原因| 倒班什么意思| 男人吃西红柿有什么好处| 身上长水泡是什么原因| 一月15号是什么星座| 太虚幻境是什么意思| 开业送什么礼物好| 肠胃功能紊乱什么症状| 甘油是什么东西| 傲慢什么意思| 口干舌燥喝水也不解渴是什么原因| 屎壳郎的学名叫什么| 舌头肥大有齿痕是什么原因| 梦见金项链是什么意思| 晚餐吃什么菜谱大全| 龙龟适合什么属相人| 久坐睾丸疼是什么原因| 胎盘位于子宫后壁是什么意思| 集体户口和个人户口有什么区别| 藏红花泡水是什么颜色| 淀粉样变性是什么病| 为什么会胸闷| 早上9点是什么时辰| 核桃什么时候吃最好| 打篮球对身体有什么好处| 什么的蜡烛| 冷血动物是什么意思| laura是什么意思| 儿童中耳炎用什么药最好| 1月1日是什么日子| 小螃蟹吃什么| 世界上最高的高原是什么| 氯是什么| 上马是什么意思| 用凝胶排出豆腐渣一样的东西是什么原因| 胃反酸吃什么食物好| 为什么会有鼻炎| 分水岭是什么意思| 白茶和绿茶有什么区别| 吐纳是什么意思| 吃什么生血| 尿常规能检查出什么| 四川是什么生肖| 血管脆是什么原因| 什么叫阳性率| 壁厚是什么意思| pop店铺是什么意思| 芭乐是什么水果| 李白被人们称为什么| 抽烟肺疼是什么原因| 多愁善感的动物是什么生肖| 鲜卑人是现在的什么人| 身份证上x代表什么| 孕期腰疼是什么原因| 梦见给别人钱是什么意思| 溢字五行属什么| 儿童头疼挂什么科| 长期吃阿司匹林有什么副作用| 韩红是什么军衔| 左眼皮跳是什么意思| 退步是什么意思| 宵字五行属什么| 市政府秘书长什么级别| top1是什么意思| 无锡为什么叫无锡| 包皮炎挂什么科| 梦见生小孩是什么征兆| 酥油是什么做的| 罗马布是什么面料| 百度
rfc:remove_object_auto_vivification

闽商许万强:以科技创新和理想信念为两翼 “走进非洲”谋新幸福

Introduction

百度   【环球时报综合报道】英国广播公司(BBC)3月22日文章,原题:毕加索为何在亚洲那么受欢迎?毕加索不仅在西方家喻户晓。

When assigning a property to a falsy value, PHP will currently convert the falsy value into an stdClass object and emit a warning. This RFC proposes to remove this “auto-vivification” behavior, and make changes to object write semantics made possible by the removal of this functionality.

An example of the current behavior is shown in the following:

$val = null;
$val->foo = 42; // Warning: Creating default object from empty value
var_dump($val); // object(stdClass)#1 (1) { ["foo"]=> int(42) }
 
$val = "";
$val->bar = 42; // Warning: Creating default object from empty value
var_dump($val); // object(stdClass)#1 (1) { ["bar"]=> int(42) } 
 
$val = "foo";
$val->abc = 42; // Warning: Attempt to assign property 'abc' of non-object
var_dump($val); // string(3) "foo"

In the first two cases, the value is falsy and a property assignment results in the creation of an object. In the last case, the value is truthy and no implicit conversion into an object occurs.

The auto-vivification behavior places a somewhat subtle requirement on the interpretation of property assignments: Normally, when performing an $obj->prop = $val operation, this only modifies the object stored in $obj, but does not modify the storage location of $obj itself. After the operation, $obj will always point to the same object, even if that object has undergone internal state changes.

However, the existence of auto-vivification makes this not strictly true: If $obj is a falsy value, then it will be converted into an object, and that requires changing the storage location of $obj itself. This distinction doesn't matter in most cases, but can be observed when magic __get() (or ArrayAccess offsetGet) is used:

class Magic {
    public $data = [];
    public function __get($key) {
        return $this->data[$key];
    }
}
 
$magic = new Magic;
$magic->data["arrayOfObj"] = [new stdClass];
$magic->arrayOfObj[0]->prop = 123;
// Notice: Indirect modification of overloaded property Magic::$arrayOfObj has no effect
 
var_dump($magic);
// object(Magic)#1 (1) {
//   ["data"]=> array(1) {
//     ["arrayOfObj"]=> array(1) {
//       [0]=> object(stdClass)#2 (1) {
//         "prop"]=> int(123)
//       }
//     }
//   }
// }

In this example, the assignment to $magic->arrayOfObj[0]->prop generates an “indirect modification has no effect” notice, while the object it still successfully modified. The reason for this behavior is that the assignment needs to fetch $magic->arrayOfObj[0] for-write on the off-chance that a falsy value will have to be converted into an object.

Proposal

Remove object auto-vivification

Assigning a property to a falsy value will no longer result in an implicit creation of an object. Returning to the example from the introduction, the new behavior is consistent for the three cases:

$val = null;
$val->foo = 42; // Warning: Attempt to assign property 'foo' of non-object
var_dump($val); // NULL
 
$val = "";
$val->bar = 42; // Warning: Attempt to assign property 'bar' of non-object
var_dump($val); // string(0) ""
 
$val = "foo";
$val->abc = 42; // Warning: Attempt to assign property 'abc' of non-object
var_dump($val); // string(3) "foo"

Fetch LHS of property assignments for-read

When performing $a->b = $c, fetch $a for-read rather than for-write. This means that the magic __get() example above will no longer generate a notice.

The other side-effect of this change is that invalid accesses on the left hand side of the assignment will now be reported. Consider this example, where $abc is assumed to be an undefined variable:

$abc["foo"]->bar = 42;
// Before this RFC:
// Warning: Creating default object from empty value
 
// After this RFC:
// Notice: Undefined variable: abc
// Warning: Attempt to assign property 'bar' of non-object 

Previously this only generated the “creating default object” warning, because for-write fetches suppress most other types of diagnostics. With this RFC the fetch is performed for-read and the use of an undefined variable is reported properly.

SimpleXML

SimpleXML, through liberal application of overloaded object handlers, allows creating deeply nested structures using a single assignment:

$xml = new SimpleXMLElement('<collection></collection>');
$xml->movie[]->characters->character[0]->name = 'Tom Hanks';
echo $xml->asXml();

This snippet generates the following XML:

<?xml version="1.0"?>
<collection><movie><characters><character><name>Tom Hanks</name></character></characters></movie></collection>

This functionality is currently implemented under the assumption that everything is fetched for-write, while this RFC proposes to fetch the $xml->movie[]->characters->character[0] portion of the access for-read. This will result in a “Cannot use [] for reading” compile-time error.

However, even if the code is adjusted to use $xml->movie[0] rather than $xml->movie[] (which is at least legal as far as the compiler is concerned), restoring the previous behavior here will still be something of a challenge.

I'm unsure what to do about this as yet.

Backward Incompatible Changes

The removal of object auto-vivification is a backwards compatibility break, which is why this RFC targets PHP 8. All cases where the behavior will change already generate a warning in PHP 7.4.

The change to read/write semantics should be backwards compatible apart from additional warnings or notices being thrown. However, it may impact extensions that rely on the current behavior, such as the SimpleXML example given above. I'm not aware of other any specific other extension being impacted.

Vote

Vote might have to be split for just the auto-vivification change (which should be a no-brainer) and the write-semantics change (which has the unfortunate interaction with SimpleXML).

rfc/remove_object_auto_vivification.txt · Last modified: by 127.0.0.1

?
结局he是什么意思 麒麟儿是什么意思 胡子长得快是什么原因 鳞状上皮细胞是什么意思 吃什么东西补钙
巴洛特利为什么叫巴神 夜来香是什么花 安大爷是什么意思 7月7日是什么星座 反讽是什么意思
焦虑抑郁症吃什么药 上热下寒吃什么食物好 倒模是什么意思 棉纺是什么面料 什么是性上瘾
办理港澳通行证需要什么证件 射手男喜欢什么样的女生 那悲歌总会在梦中惊醒是什么歌 bpo是什么意思 英短蓝猫吃什么猫粮好
肝脏低密度灶是什么病hcv9jop0ns7r.cn 拔指甲挂什么科cj623037.com 清洁度iv是什么意思chuanglingweilai.com 女人为什么会叫hcv9jop6ns6r.cn 高密度脂蛋白高是什么原因hcv8jop5ns8r.cn
梦见黑棺材是什么征兆bjhyzcsm.com 补气吃什么好hcv9jop1ns5r.cn 九十岁老人称什么hcv9jop6ns1r.cn 八段锦是什么creativexi.com 老放屁吃什么药hcv8jop7ns0r.cn
毛尖茶属于什么茶hcv9jop6ns8r.cn innisfree是什么牌子的化妆品hcv9jop4ns6r.cn 石榴什么时候开花hcv9jop0ns7r.cn 什么生肖带红花hcv8jop8ns7r.cn 脚掌疼是什么原因hcv8jop1ns3r.cn
宝宝大便有泡沫是什么原因hcv8jop8ns2r.cn 扁桃体发炎发烧吃什么药hcv8jop8ns7r.cn 盆腔积液吃什么药效果好hcv8jop9ns5r.cn 一九六三年属什么生肖hcv8jop6ns6r.cn 什么树没有叶hcv8jop3ns8r.cn
百度