Note for the zend folks: I am hoping this won't turn out to be a ZF specific question as I can see this is purely related to PHP (or in general an OOP) but added ZF tag just to see if there is something else I am missing

对于zend人员的注意事项:我希望这不会成为特定于ZF的问题,因为我可以看到这与PHP(或通常是OOP)纯粹相关,但添加了ZF标记只是为了查看是否还有其他问题我失踪了

I am creating a project in ZF 2 where I have a class which is implementing an interface called Service aware class Zend\ServiceManager\ServiceLocatorAwareInterface

我在ZF 2中创建了一个项目,我有一个类,它实现了一个名为Service aware class Zend \ ServiceManager \ ServiceLocatorAwareInterface的接口

Where this interface is very simple

这个界面非常简单

<?php
/**
 * Zend Framework (http://framework.zend.com/)
 *
 * @link      http://github.com/zendframework/zf2 for the canonical source repository
 * @copyright Copyright (c) 2005-2013 Zend Technologies USA Inc. (http://www.zend.com)
 * @license   http://framework.zend.com/license/new-bsd New BSD License
 */

namespace Zend\ServiceManager;

interface ServiceLocatorAwareInterface
{
    /**
     * Set service locator
     *
     * @param ServiceLocatorInterface $serviceLocator
     */
    public function setServiceLocator(ServiceLocatorInterface $serviceLocator);

    /**
     * Get service locator
     *
     * @return ServiceLocatorInterface
     */
    public function getServiceLocator();
}

and my implementor class is this (I have removed everything else from this class for the sake of debugging, right now this is full length code in my class)

我的实现者类就是这个(为了调试,我已经从这个类中删除了其他所有东西,现在这是我班上的全长代码)

<?php
namespace FileServer\Service;

use Zend\ServiceManager\ServiceLocatorAwareInterface;
use Zend\Di\ServiceLocatorInterface;

class Data implements ServiceLocatorAwareInterface{

    protected $sl;

    public function setServiceLocator(ServiceLocatorInterface $serviceLocator)
    {
        $this->sl = $serviceLocator;
    }

    public function getServiceLocator()
    {
        return $this->sl;
    }

}

and I have an include statement in the index.php

我在index.php中有一个include语句

include( 'E:\myproject\module\FileServer\src\FileServer\Service\Data.php' )

which is throwing PHP fatal error. Below is the complete error message

这是抛出PHP致命错误。以下是完整的错误消息

Fatal error: Declaration of FileServer\Service\Data::setServiceLocator() must be compatible with Zend\ServiceManager\ServiceLocatorAwareInterface::setServiceLocator(Zend\ServiceManager\ServiceLocatorInterface $serviceLocator) in E:\myproject\module\FileServer\src\FileServer\Service\Data.php on line 23

致命错误:FileServer \ Service \ Data :: setServiceLocator()的声明必须与E:\ myproject \ module \ FileServer \ src \ FileServer \中的Zend \ ServiceManager \ ServiceLocatorAwareInterface :: setServiceLocator(Zend \ ServiceManager \ ServiceLocatorInterface $ serviceLocator)兼容第23行的Service \ Data.php

As you can see I am implementing both the getter and setter functions with proper signature but still getting the error. What I am missing/overlooking here?

正如您所看到的,我正在使用适当的签名实现getter和setter函数,但仍然会收到错误。我错过了什么/在这里俯瞰?

1 个解决方案

#1


1

Replace:

更换:

use Zend\Di\ServiceLocatorInterface;

With:

附:

use Zend\ServiceManager\ServiceLocatorInterface;

As thats the proper interface the method is expecting. Even though they have the same name, the namespace differs.

因为这是该方法所期望的适当接口。即使它们具有相同的名称,命名空间也会有所不同。

更多相关文章

  1. 支付宝手机接口,服务端PHP验证失败,求助
  2. JSON解析错误:无法识别的标记'<'处于角度
  3. 在提交注册表单时使用jQuery显示错误
  4. 获取所有网站的错误,[重复]
  5. 如何让jQuery ajax执行错误功能
  6. Yii 访问 Gii(脚手架)时出现 403 错误
  7. PHP强大包括处理错误?
  8. php面向对象之抽象类和接口理解
  9. 您是否认为PHP中的错误形式是在类方法中访问超级全局变量?

随机推荐

  1. android设备连接到pc进行应用程序调试
  2. 使用Kotlin开发android学习记录(一)
  3. Android 游戏开发的一些基础和个人经验
  4. Android - 图解向 Android Studio 中导入
  5. android Glide简单使用
  6. 在Android平台上实现条型码扫描与识别
  7. Android2.3发布
  8. Android 布局之LinearLayout和RelativeLa
  9. Android 2.2新增Widget之ProtipWidget源
  10. Android启动脚本init.rc