sevavietl/type-casting
Composer 安装命令:
composer require sevavietl/type-casting
包简介
README 文档
README
Neither real covariance in method return type hints, nor explicit type casting are supported in PHP.
Sometimes it is useful to downcast object, so PhpStorm or PHPStan stop complaining about absent methods or mismatched types.
Usually @var tag used for this. But as with all phpdoc tags in regard of typing, this is simply telling your IDE or static analyzer tool to take your honest word that you know for sure the type of the stuff.
Whereas with actual type casting (like say in java, C# or even in PHP, but only for primitives) you can be sure that object (or primitive) is "castable" into specified type, or end up with exception.
So you can plug \TypeCasting\TypeCasting trait into your class (but only one per inheritance chain) and then use cast method that is a bit like Java.lang.Class.cast method (but of course this is oversimplified comparison).
统计信息
- 总下载量: 3
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 4
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2018-11-03
