php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #21555 Possible extensions to alternative control syntax
Submitted: 2003-01-09 15:48 UTC Modified: 2012-09-22 09:26 UTC
Votes:6
Avg. Score:4.0 ± 0.8
Reproduced:6 of 6 (100.0%)
Same Version:3 (50.0%)
Same OS:4 (66.7%)
From: gabe at bravenet dot com Assigned:
Status: Duplicate Package: *General Issues
PHP Version: 4.3.0 OS: All
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
17 + 32 = ?
Subscribe to this entry?

 
 [2003-01-09 15:48 UTC] gabe at bravenet dot com
The alternative control structure syntax (see http://php.benscom.com/manual/en/control-structures.alternative-syntax.php)  is very useful for templating purposes. However, I miss the smarty-style 'else' clauses: foreachelse, whileelse etc.

I would like to be able to do this:

<?php foreach($array as $item): ?>
// if array has items, this is repeated once per item

<?php foreachelse: ?>
// we get here if $array has no items, then exit

<?php endforeach; >

...or this...

<?php while($something == $somestate): ?>
// repeated while condition is met

<?php whileelse: ?>
// if condition is never met we go here once and exit.

<?php endwhile; ?>

I think these additions would be fairly useful.

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2012-09-22 09:26 UTC] nikic@php.net
Closing as duplicate of https://bugs.php.net/bug.php?id=26411. (This bug is older, but the other one has more discussion.)
 [2012-09-22 09:26 UTC] nikic@php.net
-Status: Open +Status: Duplicate -Package: Feature/Change Request +Package: *General Issues
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Thu Mar 28 15:01:29 2024 UTC