Req #42197 [Com]: header() cannot be used after echo on CLI

From: Date: Fri, 02 May 2014 12:54:46 +0000
Subject: Req #42197 [Com]: header() cannot be used after echo on CLI
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-185580@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=42197&edit=1 ID: 42197 Comment by: mijahn dot ben at gmail dot com Reported by: cweiske@php.net Summary: header() cannot be used after echo on CLI Status: Open Type: Feature/Change Request Package: *General Issues Operating System: Linux PHP Version: 5.2.4RC1 Block user comment: N Private report: N New Comment: Output buffering impedes the ability to view line by line errors when CLI unit testing. Previous Comments: ------------------------------------------------------------------------ [2013-07-03 12:50:13] cweiske@php.net Using ob_start() is a workaround, not a fix. Also, error messages are hidden when using ob_start(). ------------------------------------------------------------------------ [2013-06-27 22:41:26] yohgaki@php.net Just use ob_start(). $ ./sapi/cli/php <?php ob_start(); echo 'a'; header('sadf'); ?> a ------------------------------------------------------------------------ [2007-08-04 14:03:29] jani@php.net Reclassified. ------------------------------------------------------------------------ [2007-08-03 09:53:44] cweiske@php.net Description: ------------ When issuing a header() call in a php command line script (php cli) after I used 'echo', the message 'headers already sent' pops up. It should be possible to use header(), session_id_generate() and other session related functions after outputting something on CLI - since headers are not sent on cli. (The use case we have is unit-testing packages on cli) Reproduce code: --------------- <?php echo 'a'; header('sadf'); ?> Expected result: ---------------- a Actual result: -------------- a Warning: Cannot modify header information - headers already sent by (output started at /data/cvs/pear/sessionbug.php:2) in /data/cvs/pear/sessionbug.php on line 3 Call Stack: 0.0003 83688 1. {main}() /data/cvs/pear/sessionbug.php:0 0.0006 83988 2. header() /data/cvs/pear/sessionbug.php:3 ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=42197&edit=1

« previous php.bugs (#185580) next »