Req #69695 [Opn]: It should be possible to use a foreach statement to build cases in a switch

From: Date: Sun, 24 May 2015 02:31:07 +0000
Subject: Req #69695 [Opn]: It should be possible to use a foreach statement to build cases in a switch
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-192844@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=69695&edit=1

 ID:                 69695
 User updated by:    joshua dot and dot delaine at gmail dot com
 Reported by:        joshua dot and dot delaine at gmail dot com
 Summary:            It should be possible to use a foreach statement to
                     build cases in a switch
 Status:             Open
 Type:               Feature/Change Request
 Package:            Arrays related
 Operating System:   OpenSuSE 13.2
-PHP Version:        5.6.9
+PHP Version:        5.6.1
 Block user comment: N
 Private report:     N

 New Comment:

Changed version to correct version for my server's install.


Previous Comments:
------------------------------------------------------------------------
[2015-05-24 02:29:43] joshua dot and dot delaine at gmail dot com

Note: I have since tested on my test server just running the PHP command from the command line. I
get 

PHP Parse error: syntax error, unexpected 'foreach' (T_FOREACH), expecting case (T_CASE)
or default (T_DEFAULT) or '}' in /srv/www/htdocs/test.php on line 30

So Dreamweaver was right about this not working. Sadly, I know I could iterate multiple switches,
but clearly I can't iterate cases inside a switch. I bet I couldn't even do it via an
include.

------------------------------------------------------------------------
[2015-05-23 23:10:55] joshua dot and dot delaine at gmail dot com

Description:
------------
I am co-author of a custom CMS and I have just recently started to go back and revise it. I wanted
to streamline the code to make the CMS not care what the database structure it has to work with is.
There are a couple functions to get tables and get id fields and so-on, which rely on switches. This
is necessary for clean code, to say the least. As it stands, I have to know in advance the table
names, id fields, and description fields to manually modify these functions for each install of the
CMS. It would be far superior if I could use an array generated by querying the database for tables,
only knowing the name of the database. Additionally, as long as a coherent field name system was
adhered to, with specific key character groups in the names, it would be possible to get the id and
description fields with a slightly more complicated database query on the tables returned to get the
fields that either ended in, for example "id" or "desc" to list all the id and
discription co!
 lumn names in an array to be used to generate the cases for the respective switches in those
functions as well.


---
From manual page: http://www.php.net/control-structures.switch
---


Test script:
---------------
The following link shows what one of the current functions looks like vs what I'd like to be
able to do. If this is already possible, please forgive me. While a host on linux, I write code in
Adobe Dreamweaver CS6 on a Windows box. It may have outdated syntax checking.

http://pastebin.com/qkyM7TS1

Actual result:
--------------
When I try to code it, Dreamweaver CS6 syntax checking breaks. It won't do any more checking
until the supposed syntax error is corrected. I have not yet tried to put a test of the preferred
method on my test server.


------------------------------------------------------------------------



--
Edit this bug report at https://bugs.php.net/bug.php?id=69695&edit=1


Thread (4 messages)

« previous php.bugs (#192844) next »