简体   繁体   English

ArrayAccess是否扩展了Traversable?

[英]Does ArrayAccess extend Traversable?

Does ArrayAccess extend Traversable ? ArrayAccess扩展了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. ArrayAccess页面并不表示它扩展了Traversable,但是也没有明确拒绝它。 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. 我问是因为我有可以采用Traversable或ArrayAccess的代码,并且我想确保需要同时测试两者。

Short answer No. 简短的答案号

for what you need you can use arrayiterator http://php.net/manual/en/class.arrayiterator.php 对于您所需要的,您可以使用arrayiterator http://php.net/manual/zh/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. 更进一步,在即将到来的PHP 7中,我们还可以使用类型提示(对象和标量)和返回类型来进一步确保具体实现遵守合同。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM