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
 [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-2017 The PHP Group
All rights reserved.
Last updated: Sun Nov 19 01:31:42 2017 UTC