蚊子喜欢什么血型的人| 75岁属什么| 鼻炎和鼻窦炎有什么区别| 为什么手上会长小水泡| 眼睛周围长脂肪粒是什么原因| lh是什么激素| 茶水费是什么意思| 可遇不可求是什么意思| 不适随诊是什么意思| 肺在什么位置图片| miles是什么意思| 淋巴滤泡增生是什么意思严重吗| 脂肪肝中医叫什么名字| 姜什么时候种植最好| 膀胱炎尿道炎吃什么药| 三个毛念什么字| 梦见拖地是什么意思| 桔子什么时候成熟| 经常喝咖啡有什么好处和坏处| 细胞角蛋白19片段是什么意思| 头孢什么样子图片| 什么药降肌酐最有效| 倒睫是什么意思| 甲状腺结节吃什么药| 不放屁是什么原因| 凌空什么什么| 为什么不建议治疗幽门螺杆菌| 拉屎发黑是什么原因| 知了猴有什么营养| 什么茶能去体内湿气| 腰肌劳损有什么症状| 石人工念什么| 每天吃黄瓜有什么好处| 什么是占有欲| 痛经是什么引起的| 灯火通明是什么生肖| 醋酸纤维是什么面料| 上校是什么级别| 化验肝功挂什么科| 女朱读什么| 什么是药食同源| 乳房胀痛什么原因| 多尔衮是什么意思| 性功能下降是什么原因| 男性肾虚有什么症状| 传字五行属什么| 做梦梦见离婚是什么意思| 脱脂牛奶是什么意思| 有气质是什么意思| mask是什么意思| 45岁属什么| 血小板减少是什么症状| 肝囊肿挂什么科| 什么十分什么| 坐以待毙是什么意思| 胡麻是什么植物| 1992年属猴的是什么命| 为什么会落枕| 走路出汗多是什么原因| 感冒有痰吃什么药| 奥斯卡是什么意思| gpd是什么意思| 苟且是什么意思| 鼓风机是干什么用的| 木志读什么| 孙权字什么| 1014是什么星座| 左侧淋巴结肿大是什么原因| 德不配位是什么意思| 方言是什么意思| 前置是什么意思| imax电影是什么意思| 吃什么降尿酸最有效| 夏天可以玩什么| april什么意思| 格林巴利综合症是什么病| 户籍地填什么| 反复发烧是什么原因| 蒸馏水敷脸有什么作用| 助听器什么牌子好用| 草字头加青读什么| 尿血是什么症状| 什么样的教诲| 夏天适合吃什么菜| 树叶又什么又什么| 宜祭祀是什么意思| 相爱相杀是什么意思| 吃什么可以降血脂| 左耳嗡嗡响吃什么药| dsa检查是什么| 睡眠障碍挂什么科| 天蝎属于什么象星座| 练字用什么笔好| 古尔丹代价是什么| 女生肾疼是什么原因| 咩是什么意思| 智齿拔了有什么影响| 阴阳和合是什么意思| 无毒不丈夫是什么意思| 芬必得是什么药| 女人为什么会来月经| kids是什么牌子| 通讯地址填什么| 新陈代谢慢吃什么药| 早泄是什么意思| 看望老人买什么礼物好| 吃脆骨有什么好处| 夏吃姜有什么好处| 小动脉瘤是什么意思| 蚂蚁代表什么生肖| 看头发应该挂什么科| 什么是逻辑思维| 看腰挂什么科| 复刻版是什么意思| 胰岛素是干什么的| 先锋霉素又叫什么| 什么年龄割双眼皮最好| 乘风破浪什么意思| 身主天机是什么意思| 黑洞是什么| cnc是什么牌子| 小壁虎吃什么| 漂白粉是什么| 台启是什么意思| 做梦梦到猪是什么意思| 热辐射是什么| 登对是什么意思| 老人大小便失禁是什么原因造成的| 一日无书下一句是什么| 敦伦是什么意思| vjc是什么品牌| 公章一般是什么字体| 伤口撒什么药粉好得快| degaia是什么牌子| 喘不上气挂什么科| 什么是乳胶床垫| 什么是白带| 梦见车丢了是什么征兆| 脑供血不足有什么症状| 天秤座和什么星座最不配| 脚痒脱皮是什么原因| 小路像什么| 孕晚期头晕是什么原因| 一个火一个斤念什么| 农历7月25日是什么星座| rv是什么意思| 男性尿频尿急吃什么药| 沙僧属什么生肖| 枯木逢春是什么意思| 锁舌是什么| 叶什么什么龙| 糙米是什么| 什么手表品牌最好| 食禄是什么意思| 什么是肺炎| 安宫丸什么时候吃效果是最佳的| 什么叫种水| 吃过期药有什么危害| 唾液酸苷酶阳性什么意思| 长期贫血对身体有什么危害| 什么情况下做肠镜| bb霜是什么| 焦亚硫酸钠是什么| 盆腔积液吃什么消炎药| 什么可以保护眼睛| 知了猴是什么东西| 胸腔积液叩诊什么音| 比细菌还小的东西是什么| mac版本是什么意思| 94岁属什么| 第二视角是什么意思| 什么是钙化点| 舌头发麻是什么病兆| 放的屁很臭是什么原因| 甲状腺挂什么科| 卵巢无回声是什么意思| 外痔是什么样子的| 爆血管是什么原因引起的| 为什么会长痘痘| 让心归零是什么意思| 小狗感冒吃什么药| 马上风是什么意思| 妈妈的姑姑叫什么| 士官是什么级别| 基因病是什么意思| 昏什么昏什么| 宁夏有什么特产| 5月8日什么星座| 什么酒好喝| 爱情鸟是什么鸟| 和什么细什么| 脚指甲盖凹凸不平是什么原因| 淋巴组织增生是什么意思| 脚上为什么会长鸡眼| 什么地叹气| 失眠吃什么中药| 鸡蛋黄发红是什么原因| 没品什么意思| 转氨酶高吃什么好得快| ko是什么意思啊| 做b超为什么要憋尿| 牙冠什么材质的好| 胎动频繁是什么原因| 屎是什么味道的| 经常肚子疼拉肚子是什么原因| 好运连绵是什么意思| 身份证前六位代表什么| 为什么会得高血压| mtt什么意思| 口臭吃什么好| 黑枸杞的功效是什么| 身上皮肤痒是什么原因| 1037年属什么生肖| 12月8号什么星座| 什么是炎症| 背靠背协议是什么意思| 驿站是什么意思| 甯是什么意思| 地黄长什么样子图| 尼龙属于什么材料| 雄性激素过高是什么原因| 敏感水体是什么意思| 吃什么补眼睛| 北宋六贼为什么没高俅| 通透是什么意思| 我追呀追呀是什么歌曲| 什么杯子喝水最健康| 扑尔敏的学名叫什么| 限量版是什么意思| 苯是什么味道| 孕晚期羊水多了对宝宝有什么影响| 射手和什么星座最配| 右边肋骨下面是什么器官| 蓝莓有什么好处| 白癜风是什么原因引起的| ats是什么意思| 痃癖是什么病| 2031年是什么年| 22年什么婚| 经常晕车是什么原因| 砖红色是什么颜色| 炒面用什么面条最好| 耳前瘘管有什么危害| 眼睛干涩用什么药效果好| 洁颜油是干什么用的| 植村秀属于什么档次| 现在吃什么水果| 胰腺炎为什么喝水就死| dic是什么| 哔哩哔哩是什么| 发烧吃什么药| 住房公积金缴存基数是什么意思| 营养心脏最好的药是什么药| 恪尽职守什么意思| 什么是结核病| 逼是什么| 2018属什么生肖| 床塌了有什么预兆| 孤单的反义词是什么| 大限是什么意思| anker是什么牌子| 手脱皮用什么药膏最好| 嘴唇发紫是什么原因引起的| 颈部ct能检查出什么| 百度
rfc:short-closures

首轮中美执法及网络安全对话在美国华盛顿举行

Introduction

百度   建立新的案件分配机制  完善案件分配机制是检察官办案责任制改革的重要内容。

Callables syntactically have few ways of passing them around. This RFC is supposed to introduce unified short way of creating closures from callables and reduce callable type hint checks at runtime by using closures.

Proposal

Current callable syntax

Currently there are 6 available ways of declaring callables and they differ while using function or method.

namespace Util {
    function writeln(string $message) : void {
        echo $message . \PHP_EOL;
    }
 
    class Terminal {
        public static function println(string $message) : void {
            echo $message . \PHP_EOL;
        }
        public function writeln(string $message) : void {
            echo $message . \PHP_EOL;
        }
    }
 
    class Console extends Terminal {
        public function __invoke(string $message) : void {
            echo $message . \PHP_EOL;
        }
    }
}
 
namespace {
    function helloWorld(callable $callable) : void {
        $callable('Hello World!');
    }
}

Simple callback

A simple callback is possible to pass using their name.

helloWorld('Util\\writeln');
call_user_func('Util\writeln', 'Hello World!');

Static class method call

Static class method call first way is quite similar and requires method name after ::.

helloWorld('Util\\Terminal::println');
call_user_func('Util\\Terminal::println'), 'Hello World!');

Static class method call using array

Static class method call can be also passed using array construct with a class name at 0 index and method name at 1 index.

helloWorld([Util\Terminal::class, 'println']);
call_user_func([Util\\Terminal::class, 'println']), 'Hello World!');

Object method call

Object method call is passed using array construct with two params - which is object instance variable and method name.

$terminal = new \Util\Terminal();
helloWorld([$terminal, 'writeln']);
call_user_func([$terminal, 'writeln'], 'Hello World!');

Relative static class method call

Relative static class method call is passed using array with two params - which is class name and method name with base class name delimited by ::.

$console = new Util\Console();
call_user_func([Util\Console::class, 'parent::writeln'], 'Hello World!');

Invokable objects

Objects implementing '__invoke' can be used as callables using an instance variable.

$console = new Util\Console();
helloWorld($console);
call_user_func($console, 'Hello World!');

Drawbacks of current solution

  1. The syntax is based on passing function names as a string or array with an instance and method name as a string etc. which is very hard to refactor using for eg. IDE or detecting using regular expressions.
  2. Passed callables are different type variables, like: 'string', 'array' or specified object instance.
  3. Passed callables may not be valid callables which are validated at call time and can pass callable type hint without warning.

Proposed solution

The way to unify passing callables is creating closures using the same syntax as invoking functions without their argument list and parenthesis around braces and call them all the same way, which benefits are short closure from callable syntax which shortens creation of closures for most of the cases.

Simple callback

Short closure from callable function would look like:

$writeln = {Util\writeln};
// is a simplification for
$writeln = Closure::fromCallable('Util\writeln');

Static class method call

Static class method short closure that would look like:

$println = {Util\Terminal::println};
// instead of
$println = Closure::fromCallable([Util\Terminal::class, 'writeln']);
// and
$println = Closure::fromCallable('Util\Terminal::writeln');

Object method call

Object instance method short closure that would look like:

$writeln = {$terminal->writeln};
// instead of
$writeln = Closure::fromCallable([$terminal, 'writeln']);

Invokable objects

Invokable objects short closure that would be:

$console = new Util\Console();
$callback = {$console};
// instead of
$callback = Closure::fromCallable($console);

Benefits

  1. Every callable closure is valid for all the time when it's passed around.
  2. No need to validate callable type hint against given argument every time.
  3. Common syntax for most of the callable types.
  4. Syntax similar to function/method call.
  5. No need to pass function/method/class names as strings which are not IDE friendly for refactoring.
  6. Easy to parse by static analysis tools because of consistent syntax.

Backward Incompatible Changes

None

Proposed PHP Version(s)

The proposed PHP versions that the feature will be included is “next PHP 7.x” or “PHP 8.0”.

RFC Impact

To SAPIs

None.

To Existing Extensions

No.

To Opcache

Isn't verified yet.

New Constants

None.

php.ini Defaults

None.

Open Issues

None.

Unaffected PHP Functionality

None.

Future Scope

There might be additional reflection inprovement which gives ability to retrieve information about closure origin.

Proposed Voting Choices

As this is a language change, a 2/3 majority is required. The vote would be a straight Yes/No vote for accepting the RFC and merging the patch.

Patches and Tests

Not implemented

References

Links to external references, discussions or RFCs
rfc/short-closures.txt · Last modified: by 127.0.0.1

?
函询是什么意思 苏轼为什么反对王安石变法 乳头痒是怎么回事是什么原因 腺样体增生是什么意思 扁桃体切除有什么坏处
cin是什么意思 天津市市长什么级别 吃开心果有什么好处和坏处 髋关节弹响是什么原因 看指甲挂什么科
先兆流产是什么原因 尿酸吃什么药 缺钾吃什么 非营利性医院是什么意思 做梦吃面条是什么预兆
摩羯前面是什么星座 六月十二日是什么日子 cmr医学中什么意思 眼睛有血丝是什么原因 白薯是什么
嗓子疼发烧吃什么药hcv9jop4ns7r.cn 教师资格证有什么用hcv8jop1ns8r.cn 穿匡威的都是什么人hcv8jop3ns0r.cn 汉尼拔是什么意思hcv8jop8ns2r.cn 火疖子是什么hcv8jop4ns9r.cn
无药可救是什么意思hcv9jop1ns1r.cn 法国的货币叫什么hcv7jop5ns0r.cn 孕妇做春梦是什么意思hcv7jop7ns4r.cn 股骨头坏死是什么原因引起的jingluanji.com 小孩啃指甲是什么原因xinjiangjialails.com
hpv59高危阳性是什么意思hcv9jop7ns3r.cn 寡糖是什么糖kuyehao.com 拉尿分叉是什么原因hkuteam.com 有容乃大什么意思hcv8jop9ns7r.cn 肚子不饿是什么原因hcv9jop0ns1r.cn
11号来月经什么时候是排卵期hcv8jop7ns6r.cn 什么水果贵hcv8jop9ns3r.cn 小孩脸上长痣是什么原因引起的hcv8jop6ns0r.cn 谁也不知道下一秒会发生什么hcv9jop2ns5r.cn 失代偿期是什么意思chuanglingweilai.com
百度