【发布时间】:2017-01-25 11:22:40
【问题描述】:
最近我在 Ubuntu 12.04 LTS 上如 link 中所述升级到 Php 5.4:-
sudo add-apt-repository ppa:ondrej/php5-oldstablesudo apt-get updatesudo apt-get dist-upgrade
我的代码没有任何改变。但现在我收到以下错误:-
E_WARNING Cannot modify header information - headers already sent by (output started at Abstract.php:588) in functions.php on line 55
引发错误的相关代码:-
//Abstract.php
public function outputBody()
{
$body = implode('', $this->_body);
echo $body; //Line 588
}
...
// functions.php
if ($exit) {
if (strtolower(PHP_SAPI) != 'cli') {
header("HTTP/1.1 500 Internal Server Error"); //Line 55
}
echo Bob_Exception_Helper::printException($e, $logStr) . PHP_EOL;
exit (1);
}
我在/etc/php5/cli/php.ini 和/etc/php5/apache2/php.ini 中都添加了以下行,如this 问题中所述
output_buffering = On
在 php 5.3 上一切正常。升级后没有进行任何代码更改。刚升级到 PHP 5.4 后,这个问题就出现了。
php --version
PHP 5.4.45-4+deprecated+dontuse+deb.sury.org~precise+1 (cli) (built: Jun 24 2016 08:30:18)
Copyright (c) 1997-2014 The PHP Group
Zend Engine v2.4.0, Copyright (c) 1998-2014 Zend Technologies
with Xdebug v2.2.3, Copyright (c) 2002-2013, by Derick Rethans
抛出错误的php代码:-
public function outputBody()
{
$body = implode('', $this->_body);
echo $body; //As per the warning this line is throwing the error
}
但仍然出现同样的错误?谁能告诉我如何解决这个问题?
【问题讨论】:
-
这可能会对你有所帮助 - How to fix “Headers already sent” error in PHP
-
是的,我已经解决了这个问题。更新了我的问题。
-
会有一些 PHP 代码产生这个错误 - 通常它在
E_Warning中引用 - 还有比你发布的更多吗? -
更新了问题。