PHP 5.5.9名称空间问题 [英] PHP 5.5.9 namespace issue
问题描述
我正在使用5.5.9-1ubuntu4在Ubuntu 14.04 LTS上运行apache2.
I am running apache2 on Ubuntu 14.04 LTS with 5.5.9-1ubuntu4.
我正在将工作代码上传到服务器,但收到"NetworkError:500 Internal Server Error"
I was uploading a working code to the server but got "NetworkError: 500 Internal Server Error"
所以我开始寻找问题所在.我追溯了一下,发现它似乎是名称空间声明的问题.为了弄清楚(简化事情),我创建了一个新文件来复制错误.
So I started tracking down the problem. I traced it back and found out it seems to be a problem with namespace declaration. In trying to figure it out (simplify things) I created a new file that duplicates the error.
<?php
namespace MyProject ;
echo '"', __NAMESPACE__, '"'; // outputs "MyProject"
?>
通过浏览器放置时,会产生上述错误.
When put through a browser it generates the above error.
如果我注释掉第二行,它会正常运行并产生预期的输出
If I comment out the 2nd line, it runs without error and produces the expected output
""
有什么想法吗?
推荐答案
第二行中只缺少一个分号;
:
There is just a semilicon ;
missing on the second line:
<?php
namespace MyProject ;
echo '"', __NAMESPACE__, '"'; // outputs "MyProject"
?>
您还应该在<?php
开头标记之前删除空格和空白行.
You should also get rid of the spaces and blank lines before your <?php
opening tag.
这篇关于PHP 5.5.9名称空间问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!