Skip to content
This repository has been archived by the owner on Feb 1, 2020. It is now read-only.

Implement array object compatible array functions #2

Open
kherge opened this issue Feb 22, 2018 · 1 comment
Open

Implement array object compatible array functions #2

kherge opened this issue Feb 22, 2018 · 1 comment
Assignees

Comments

@kherge
Copy link
Member

kherge commented Feb 22, 2018

Problem

If I use an array object, I am no longer able to use any of the array functions that PHP provides.

$array = new ArrayObject();

// Warning: array_search() expects parameter 2 to be array, object given
$index = array_search(123, $array);

Resolution

Implement the available array functions with support for any ArrayAccess or Iterator implementation. The implementations should default to use PHP's array_ functions if an actual array is provided.

use function KHerGe\Arrays\search;

$array = new ArrayObject();

$index = search($array, 123);

References

  1. http://php.net/manual/en/ref.array.php
@kherge kherge added the Feature label Feb 22, 2018
@kherge kherge self-assigned this Feb 22, 2018
@kherge kherge added the RFC label Feb 22, 2018
@kherge
Copy link
Member Author

kherge commented Feb 22, 2018

Some functions produce new arrays. Since array objects can have keys that are invalid for normal arrays, it may not be possible to return a normal array. Should the functions default to using AnyKey for new arrays?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

1 participant