duanhuhong5255 2013-02-13 21:19
浏览 107
已采纳

PHP命名空间不起作用 - 怀疑PHP配置问题

OK, so, I've been using auto-loaders for a while, become rather used to MVC, and decided to try to tackle namespaces. Well, this hasn't worked as expected. I have managed to reproduce the error in a very simple way, so the contents of my php file read:

<?php
namespace site\test;

echo 'hello';

The output is not what I expected:

Fatal error: Namespace declaration statement has to be the very first statement in the script in file on line 2

I'm running PHP 5.3.10 on a Synology NAS, using the latest version of DSM (Synology's OS). This makes use of Apache v2.2.22. I can confirm that commenting out the "namespace" line returns the word "hello", with no extra characters before it.

There is no BOM at the beginning of the file. I also have no issues with setting headers such as "Location" which would suggest this as being an issue.

Line endings are Unix ( only) and the character encoding of the file is UTF8.

The PHP setting "auto_prepend_file" is empty.

  • 写回答

3条回答 默认 最新

  • drip5880 2013-02-16 22:50
    关注

    A re-install of the DSM (Synology OS) actually resolved the issue. Once done, some of the classes obtained from other frameworks had the "BOM" bytes at the beginning of the file, but not all. Simple solution to the BOM issues is to add a "BOM" remover into the auto-loader.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥15 mmocr的训练错误,结果全为0
  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀