简体   繁体   English

我如何“使用” IteratorAggregate接口,PHP找不到它?

[英]How do I 'use' the IteratorAggregate interface, PHP can't find it?

I have a class that I want to implement IteratorAggregate. 我有一个要实现IteratorAggregate的类。 I declare: 我声明:

class Email implements IteratorAggregate {

but when I rung the code I get: 但是当我敲响代码时,我得到了:

Attempted to load interface "IteratorAggregate" from namespace "Companyname\\ConsoleBundle\\Entity". 尝试从名称空间“ Companyname \\ ConsoleBundle \\ Entity”中加载接口“ IteratorAggregate”。 Did you forget a "use" statement for another namespace? 您是否忘记了另一个名称空间的“使用”语句?

So what name space should I adding to implelement the 'IteratorAggregate' interface. 所以我应该添加什么名称空间来实现'IteratorAggregate'接口。 None of the examples I've seen include any use or require statements for it and it should be included as standard in PHP5 so it's not an installation issue. 我所见过的示例均未包含​​任何使用或require语句,并且应将其作为PHP5的标准包含在内,因此这不是安装问题。

Any ideas what I'm doing wrong? 有什么想法我做错了吗?

当您使用自己的名称空间并且要使用标准类时,必须像这样拼写

class Email implements \IteratorAggregate {

To "use" classes from the global namespace, prefix them with a backslash: 要从全局名称空间“使用”类,请在它们前面加上反斜杠:

use \IteratorAggregate;

class Email implements IteratorAggregate { ... } 

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

相关问题 在使用PHPUnit进行测试时,如何在使用实现IteratorAggregate接口的Mock类时防止重新声明错误? - How do I prevent redeclaration errors when using Mock classes that implement the IteratorAggregate interface when testing with PHPUnit? PHP致命错误:找不到接口“ IteratorAggregate” - PHP Fatal error: Interface 'IteratorAggregate' not found 这是什么意思?在实现接口时,在php中使用IteratorAggregate或Iterator作为其名称? - What does it mean When implementing interface use IteratorAggregate or Iterator in its name in php? 无法将新元素写入IteratorAggregate? - Can't write new elements to IteratorAggregate? 如何在 php class 中正确使用/导入接口? - How can I correctly use/import an interface in a php class? 我如何找到完成的php exec命令,以便可以使用AJAX重新呈现页面? - How do I find the php exec command is done, so that I can use AJAX to rerender page? 我如何使用PHPMailer?我在网上找不到一个简单的体面教程 - How do I use PHPMailer? I can't find a simple decent tutorial online 我找不到这个:如何在EMACS中使用4个SPACES而不是TAB? - I can't find this: How do I use 4 SPACES instead of a TAB in EMACS? 如何使用xdebug查找php内存泄漏? - How do I use xdebug to find a php memory leak? 如何在 PHP 中使用正则表达式来查找被空格包围的数字? - How do I use regex in PHP to find a number surrounded by spaces?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM