# array type hint and SPL array interfaces

- Thread: https://externals.io/message/23214
- Original archive: https://news-web.php.net/php.internals/23214
- Started by Tobias Schlitt on 2006-05-09T10:56:19+00:00
- Messages: 2
- Reply by email to internals@lists.php.net
- More for agents: search with https://externals.io/search.md?q={query} · JSON API at https://externals.io/api · documentation at https://externals.io/llms.txt

---

## #23214 — Tobias Schlitt — 2006-05-09T10:56:19+00:00

URL: https://externals.io/message/23214#23214

Hi Marcus!

I wondered, why PHP complains, if you have an array type hint in a
method prototype and provide an object to this method, that implements
the SPL interfaces to use objects as arrays. I would expect that, if an
object can be handled exactly like an array, PHP should not complain,
since the implementation of the method would not notice the difference.
Or am I wrong?

Regards,
Toby
-- 
Tobias Schlitt - Zend Certified Engineer     NEW GPG Key: 0xC462BC14
a passion for php                            http://www.schlitt.info
Like to say "thank you"?    -  http://pear.php.net/wishlist.php/toby

---

## #23215 — Jared Williams — 2006-05-09T11:17:27+00:00

URL: https://externals.io/message/23214#23215 · In reply to: #23214

> 
> Hi Marcus!
> 
> I wondered, why PHP complains, if you have an array type hint 
> in a method prototype and provide an object to this method, 
> that implements the SPL interfaces to use objects as arrays. 
> I would expect that, if an object can be handled exactly like 
> an array, PHP should not complain, since the implementation 
> of the method would not notice the difference.
> Or am I wrong?

But the method may use an array_*() function, which would cause problems if they're handed an ArrayAccess implementation. So there
is a difference.

Jared
