PHP命名空间不工作 - 怀疑PHP配置问题 [英] PHP Namespace not working - suspected PHP configuration issue

查看:807
本文介绍了PHP命名空间不工作 - 怀疑PHP配置问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

行,所以,我一直在使用自动装填了一段时间了,变得相当使用MVC,并决定尝试解决命名空间。嗯,这个预期并没有奏效。我已成功地重现错误在一个非常简单的方法,让我的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:

致命错误:命名空间声明语句必须在脚本中的第一个语句的文件第2行

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

我在一台Synology NAS上运行PHP 5.3.10,使用最新版本的DSM(Synology的OS)。这使得使用Apache v2.2.22的。我可以证实,注释掉命名空间行返回之前单词你好,没有多余的字符。

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.

有是在文件的开头没有BOM。我也没有问题与设置标题,如位置,这将表明这作为是一个问题。

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.

行尾UNIX(\\ n只)和文件的字符编码​​是UTF8。

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

在PHP设置AUTO_ prepend_file是空的。

The PHP setting "auto_prepend_file" is empty.

推荐答案

一个帝斯曼(群晖OS)的重新安装实际上解决了这个问题。一旦这样做,一些来自其他框架中获得的类有BOM字节在文件的开始,而不是全部。简单的解决方案的BOM问题是添加一个物料清单卸妆到自动加载器。

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.

这篇关于PHP命名空间不工作 - 怀疑PHP配置问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆