|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
[2019-11-11 12:30 UTC] cmb@php.net
-Status: Open
+Status: Suspended
[2019-11-11 12:30 UTC] cmb@php.net
|
|||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Sat Oct 25 19:00:01 2025 UTC |
Description: ------------ Since PHP 7.1 there's the "iterable" pseudo type hint that matches "array" and "Traversable". It would be great if PHP would support an "arrayable" pseudo type hint that matches "array" and all objects that implements "Traversable", "ArrayAccess" and "Countable". Thus, we could pass arrays or all objects that behave like arrays to methods and do: function useArrayable( arrayable $arg ) : arrayable { count( $arg ); $value = $arg['key']; foreach( $arg as $key => $entry ) { ... } return $arg; } It would be useful to implement an Arrayable interface too: interface Arrayable extends \Iterator, \Countable, \ArrayAccess { public function toArray() : array; } Then, we can use array like objects: class Test implements \Arrayable { // ... } $arrayable = new Test(); $arrayable['key'] = $value; $arrayable = useArrayable( $arrayable ); And if necessary, we can convert them to arrays: if( $arrayable instanceof \Arrayable ) { $arrayable = $arrayable->toArray(); }