php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #28381 <?= $variable ?> eats up a newline if it follows ?>
Submitted: 2004-05-13 05:44 UTC Modified: 2004-05-13 10:19 UTC
From: mikemc-phpbug2 at contactdesigns dot com Assigned:
Status: Not a bug Package: Scripting Engine problem
PHP Version: 4.3.6 OS: Linux 2.4.20-28.9smp
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: mikemc-phpbug2 at contactdesigns dot com
New email:
PHP Version: OS:

 

 [2004-05-13 05:44 UTC] mikemc-phpbug2 at contactdesigns dot com
Description:
------------
This isn't a major bug, but I would think it should be classified as a bug just so that it is on the radar screen.  For those of us too lazy to write <?php echo $variable ?> and instead prefer <?= $variable ?>, if a newline immediately follows the "?>" then PHP eats the new line :-(

Reproduce code:
---------------
vi test.php (then insert following code and :wq Enter)
<?= $_SERVER['PHP_SELF'] ?>
I should be on a new line - but I am not!
[shellprompt]# php test.php
testing.phpI should be on a new line - but I am not!


Expected result:
----------------
testing.php
I should be on a new line - but I am not!

Actual result:
--------------
testing.phpI should be on a new line - but I am not!

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-05-13 05:50 UTC] mikemc-phpbug2 at contactdesigns dot com
Almost forgot the workaround!  You can insert a space right after "?>" and the newline gets output.

Yes it is specific to newlines for example, this:

<?= $_SERVER['PHP_SELF'] ?>*
I should be on a new line - but I am not!

Outputs this:

testing.php*
I should be on a new line - but I am not!

So PHP only seems to eat the newline - it ignores the "*".  Wonder if there are any other characters it doesn't like?
 [2004-05-13 10:19 UTC] mgf@php.net
Thank you for taking the time to write to us, but this is not
a bug. Please double-check the documentation available at
http://www.php.net/manual/ and the instructions on how to report
a bug at http://bugs.php.net/how-to-report.php

Expected behaviour, documented at http://www.php.net/basic-syntax ("The closing tag for the block will include the immediately trailing newline if one is present.")
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Sat Jul 12 08:01:30 2025 UTC