php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #9576 Parse error with ($i%2) ? echo '':echo''
Submitted: 2001-03-06 07:09 UTC Modified: 2001-03-07 01:05 UTC
From: yasuo_ohgaki at hotmail dot com Assigned:
Status: Closed Package: Scripting Engine problem
PHP Version: 4.0.4pl1 OS: RedHat Linux v7.0.1/j
Private report: No CVE-ID: None
 [2001-03-06 07:09 UTC] yasuo_ohgaki at hotmail dot com
Miner parser bug.
PHP4.0.4pl1 on my Linux (PHP is running as Apache 1.3.17 module) gives parse error with following code. 

<tr class=<?php ($i % 2) ? echo('even') : echo('odd') ?>>

This one works as expected
<tr class=<?php ($i % 2) ? print('even') : print('odd') ?>>

Hope this helps.

---
Yasuo Ohgaki

=== SOURCE BEGIN ====
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=EUC-JP">
<link rel="stylesheet" href="../lib/css/std.css">
<style type="text/css">
<!--
.odd {  background: #CCCCFF}
.even {  background: #CCCCCC}
-->
</style>
</head>

<body bgcolor="#FFFFFF">
<table width="80%" border="2" cellspacing="1" cellpadding="1">
<?php
for ($i = 0; $i < 100; $i++) { ?>
<!-- <tr class=<?php if ($i % 2 == 0) echo('even'); else echo('odd'); // OK?>> -->
<!-- <tr class=<?php ($i % 2) ? print('even') : print('odd'); // OK ?>> -->
<tr class=<?php ($i % 2) ? echo('even') : echo('odd'); // NOT OK ?>>
<td>?@</td>
<td>?@</td>
</tr>
<?php
} // END for( ) loop
?>
</table>
</body>
</html>
==== END SOURCE ====

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2001-03-06 08:25 UTC] stas@php.net
echo is a statement, not a function, thus cannot be used in
an expression. You are right to use print.
 [2001-03-07 01:05 UTC] yasuo_ohgaki at hotmail dot com
Ok thanks. "echo" is not a function like "include".
(include is a language construct, right?)
Then I expect following should not work.

($some_var) ? include('ture.inc') : include('false.inc');

but, it works for some reason..... (or include() is a function?)
Not a big deal though.

Regards,
--
Yasuo Ohgaki

 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Apr 25 06:01:35 2024 UTC