PHP类型提示特征

栏目: PHP · 发布时间: 7年前

内容简介:DaveRandom不能说.你不应该.你可能想要实现一个接口和typehint.然后,您可以使用trait实现该界面.http://stackoverflow.com/questions/14157586/php-type-hinting-traits本站文章除注明转载外,均为本站原创或编译

我有一个特点.为了创造力,让我们称之为“特质”特征:

trait Trait{    
    static function treat($instance){    
        // treat that trait instance with care
    }
}

现在,我也有一个使用这个特征的类,User.当试图用即时用户来打电话时,一切正常.但是我想键入提示,只有使用特征的类的实例应该被赋予为参数,如:

static function treat(Trait $instance){...}

可悲的是,这导致了一个致命的箭头,表示该功能正在期待一个特征的实例,但是给出了一个User的实例.这种类型的提示对于继承和实现是完美的,但是如何键入 – 提示一个特征?

DaveRandom不能说.你不应该.你可能想要实现一个接口和typehint.然后,您可以使用trait实现该界面.

http://stackoverflow.com/questions/14157586/php-type-hinting-traits

本站文章除注明转载外,均为本站原创或编译

转载请明显位置注明出处:PHP类型提示特征


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Advanced Web Metrics with Google Analytics, 2nd Edition

Advanced Web Metrics with Google Analytics, 2nd Edition

Brian Clifton / Sybex / 2010-3-15 / USD 39.99

Valuable tips and tricks for using the latest version of Google Analytics Packed with insider tips and tricks, this how-to guide is fully revised to cover the latest version of Google Analytics and sh......一起来看看 《Advanced Web Metrics with Google Analytics, 2nd Edition》 这本书的介绍吧!

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试