FAQ
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

Search Discussions

  • Jared Williams at May 9, 2006 at 11:13 am

    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
  • Tobias Schlitt at May 9, 2006 at 1:07 pm
    Hi Jared Williams!
    On 05/09/06 13:17 you wrote:

    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.
    Ah, yes, you're right! Thanks for enlightening me!

    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

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupphp-internals @
categoriesphp
postedMay 9, '06 at 10:59a
activeMay 9, '06 at 1:07p
posts3
users2
websitephp.net

2 users in discussion

Tobias Schlitt: 2 posts Jared Williams: 1 post

People

Translate

site design / logo © 2022 Grokbase