dongzhaoshi8497 2014-11-23 11:13
浏览 37
已采纳

ZF2中我的module.php中的命名空间错误

Error :

Fatal error: Namespace declaration statement has to be the very first statement in the script in C:\xampp\htdocs\zf2-tutorial\module\Album\Module.php on line 8

Module.php

<?php

namespace Application;

use Zend\Mvc\ModuleRouteListener;
use Zend\Mvc\MvcEvent;

class Module
{
public function onBootstrap(MvcEvent $e)
{
    $eventManager        = $e->getApplication()->getEventManager();
    $moduleRouteListener = new ModuleRouteListener();
    $moduleRouteListener->attach($eventManager);
}

public function getConfig()
{
    return include __DIR__ . '/config/module.config.php';
}

public function getAutoloaderConfig()
{
    return array(
        'Zend\Loader\StandardAutoloader' => array(
            'namespaces' => array(
                __NAMESPACE__ => __DIR__ . '/src/' . __NAMESPACE__,
            ),
        ),
    );
  }
}

I've already checked for white spaces and as you can see namespace declaration is first after the opening php tag. Can't figure out what's causing this.

  • 写回答

1条回答 默认 最新

  • douju4594 2014-11-23 11:49
    关注

    That error is telling you that there are any output before the namespace declaration.

    Look for whitespaces before <?php in your files. This could be caused by some editors adding BOM to UTF8 files, so you should save them as "UTF8 without BOM" or "Unicode".

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥100 华为ensp只要2-9实验运行结果能做的来
  • ¥15 我这个代码哪里有问题 acm 平台上显示错误 90%,我自己运行好像没什么问题
  • ¥50 C#编程中使用printDocument类实现文字排版打印问题
  • ¥15 找会编程的帅哥美女 可以用MATLAB里面的simulink编程,用Keil5编也可以。
  • ¥15 已知隐函数其中一个变量τ的具体值,求另一个变量
  • ¥15 r语言Hurst指数
  • ¥15 Acrn IVSHMEM doorbell问题
  • ¥15 yolov5中的val测试集训练时数量变小问题
  • ¥15 MPLS/VPN实验中MPLS的配置问题
  • ¥15 materialstudio氢键计算问题