[英]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.