Re: [PHP] dynamic case statements?

2006-08-19 Thread Richard Lynch
On Fri, August 18, 2006 11:58 am, Tom Cruickshank wrote:
> Would anyone know if it's possible to have dynamic case
> statements?

Almost for sure...

I *know* you can use switch(true) and put *ANY* expression you want
for a case.

switch (true) {
  case $temp === 'status':
$theform->status();
  break;
  case $temp:
$theform->form($temp);
  break;
}

> Theform = new form();
>
> $temp = $_POST['var1'];
>switch ($temp) {
> case "status":
> $theform->status();
> break;
>
> case $temp:
> $theform->form($temp);
> break;
> }

This, however, is probably better handled with a 'default:' instead of
case $temp...

> This keeps giving me  Call to undefined method form::form() in
> /usr/local/www/data-dist/form.php on line 38

Then your class form probably does not have a function named form...

In fact, if it does, then in PHP4 that was the constructor, so you
probably can't use that for ANYTHING other than saying:
new form;

And form() gets called on 'new' and only on 'new'

-- 
Like Music?
http://l-i-e.com/artists.htm

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] dynamic case statements?

2006-08-18 Thread Tom Cruickshank
Hello,
Would anyone know if it's possible to have dynamic case statements?

For example.

Theform = new form();

$temp = $_POST['var1'];
   switch ($temp) {
case "status":
$theform->status();
break;

  case $temp:
$theform->form($temp);
break;
}

This keeps giving me  Call to undefined method form::form() in
/usr/local/www/data-dist/form.php on line 38

Line 38 is right after case $temp:

If I have case "temp": error goes away, so I get the feeling case doesn't
like the variable $temp.

Any help would be appreciated. Thanks!

Tom


-- 
No virus found in this outgoing message.
Checked by AVG Free Edition.
Version: 7.1.405 / Virus Database: 268.11.2/422 - Release Date: 8/17/2006
 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php