php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Request #42726 New foreach instruction :provide pseudo method with pseudo class foreach
Submitted: 2007-09-21 12:28 UTC Modified: 2007-09-21 14:46 UTC
From: jfcouic at hotmail dot com Assigned:
Status: Not a bug Package: Feature/Change Request
PHP Version: 5.2.4 OS: windows or all
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: jfcouic at hotmail dot com
New email:
PHP Version: OS:

 

 [2007-09-21 12:28 UTC] jfcouic at hotmail dot com
Description:
------------
Could it be possible to have a new structure instruction to "foreach" ?
I know that it possible to write with existing instructions but it could be usefull to have this one. It could easily replace some code block like "if(){try{foreach{}catch{}}}else{}" and provide more efficient and "bug disable" code...

See the code, it's only a purpose.




Reproduce code:
---------------
$ar = array(0=>"one", 1=>"two");
foreach($ar as $ix $v) {
catch begin {
   print "<table>";
   print "<caption>My array have ".count($ar)." elements</caption>";
   print "<tr><th>MyH1</th><th>...</th></tr>";
   }
catch end {
   print "</table>";
   }
catch each {
   print "<tr><th>$ix</th><th>$v</th></tr>";
   }
catch null {
   print "oups! my array is empty";
   }
catch exception $ex {
   print "oups! my code is so ugly that it done an error exception.";
   }
}

Expected result:
----------------
<table>
<caption>My array have 2 elements</caption>
<tr><th>MyH1</th><th>...</th></tr>
<tr><th>0</th><th>one</th></tr>
<tr><th>1</th><th>two</th></tr>
</table>

Actual result:
--------------
oups! this instruction do not exists.

Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2007-09-21 14:46 UTC] johannes@php.net
We can't provide special constructs for every need.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Tue Jul 01 19:01:37 2025 UTC