0

Does ArrayAccess extend Traversable? The man pages for each make no mention of the other. The ArrayAccess page does not indicate that it extends Traversable, but it doesn't explicitly deny it either. I ask because I have code that could take either Traversable or ArrayAccess, and I want to make sure that I need to test for both.

3
  • Definition of ArrayAccess is pretty obvious, isn't it? Commented Aug 27, 2018 at 15:28
  • And the man page for Traversable says, from the beginning: "Interface to detect if a class is traversable using foreach." Yet you can traverse ArrayAccess objects with foreach too. Commented Aug 27, 2018 at 15:57
  • I don't think you can. Commented Aug 27, 2018 at 16:11

1 Answer 1

1

Short answer No.

for what you need you can use arrayiterator http://php.net/manual/en/class.arrayiterator.php


  • Interfaces do not implement each other "it extends."
  • Interfaces are made to implemented or extended by developer through interface / abstract classes / classes.

interfaces are contracts that some code implements and adheres to and other code depends upon. It allows us to have assurance that any given dependency will implement the methods we expect. Even further, with the upcoming PHP 7, we can also use type hints (object and scalars) and return types to further ensure that concrete implementations adhere to the contracts.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.