linna/typed-array
Composer 安装命令:
composer require linna/typed-array
包简介
Linna Typed Array, typed arrays for PHP
关键字:
README 文档
README
About
This package provide typed arrays for php as extension of native ArrayObject.
Requirements
This package require php 8.1
Installation
With composer:
composer require linna/typed-array
Classes
| Name | Native Type Handled | Description |
|---|---|---|
ArrayOfArrays |
array | |
ArrayOfBooleans |
bool | |
ArrayOfCallable |
callable | |
ArrayOfClasses |
any existing class | passed as first argument in constructor as ::class |
ArrayOfFloats |
float | |
ArrayOfIntegers |
int | |
ArrayOfObjects |
object | |
ArrayOfStrings |
string |
Usage
use Linna\TypedArrayObject\ArrayOfIntegers; use Linna\TypedArrayObject\ArrayOfClasses; //correct, only int passed to constructor. $intArray = new ArrayOfIntegers([1, 2, 3, 4]); //correct, int assigned $intArray[] = 5; //throw InvalidArgumentException, string assigned, int expected. $intArray[] = 'a'; //correct, int used $intArray->append(5); //throw InvalidArgumentException, string used, int expected. $intArray->append('a'); //throw InvalidArgumentException, mixed array passed to constructor. $otherIntArray = new ArrayOfIntegers([1, 'a', 3, 4]); //correct, only Foo class instances passed to constructor. $fooArray = new ArrayOfClasses(Foo::class, [ new Foo(), new Foo() ]); //correct, Foo() instance assigned. $fooArray[] = new Foo(); //throw InvalidArgumentException, Bar() instance assigned. $fooArray[] = new Bar(); //correct, Foo() instance used. $fooArray->append(new Foo()); //throw InvalidArgumentException, Bar() instance used, Foo() instance expected. $fooArray->append(new Bar()); //throw InvalidArgumentException, mixed array of instances passed to constructor. $otherFooArray = new ArrayOfClasses(Foo::class, [ new Foo(), new Bar() ]);
Note: Allowed types are: array, bool, callable, float, int, object, string and all existing classes.
Performance consideration for v3.0
Compared to previous versions of the library, this version is a bit faster because every types has it own class. Do milliseconds really matters?
Performance consideration for v2.0
Compared to first version of the library, this version is a bit slower because after merging TypedObjectArray with TypedArray,
there are more code that be executed when new instance is created and on assign operations.
Performance consideration for v1.0
Compared to the parent class ArrayObject typed arrays are slower on writing
approximately from 6x to 8x. The slowness is due to not native __construct() and not native offsetSet().
Other operations do not have a speed difference with the native ArrayObject.
use Linna\TypedArray; //slower from 6x to 8x. $array = new TypedArray('int', [1, 2, 3, 4]); $array[] = 5; //other operations, fast as native. //for example: $arrayElement = $array[0]; $elements = $array->count();
View the speed test script on gist.
linna/typed-array 适用场景与选型建议
linna/typed-array 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 8.44k 次下载、GitHub Stars 达 7, 最近一次更新时间为 2017 年 06 月 12 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「array」 「Typed Array」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 linna/typed-array 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 linna/typed-array 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 linna/typed-array 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A set of useful PHP classes.
A collection package that can be extended to implement things such as a Dependency Injection Container, RecordSet objects for housing database records, a bag of http cookies, or technically any collection of items that can be looped over and whose items can each be accessed using array-access syntax
Trait providing methods to set class properties with an array.
Traits to build collections of specific objects
This adds functions about array. If you feel like there few php built-in functions about array, this will be useful.
Convert array or camel case to underscore, or underscore to others.
统计信息
- 总下载量: 8.44k
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 8
- 点击次数: 1
- 依赖项目数: 2
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2017-06-12

