From:             webmaster at jaimemontoya dot com
Operating system: FreeBSD
PHP version:      4CVS-2008-01-21 (CVS)
PHP Bug Type:     PHP options/info functions
Bug description:  switch with rand() function don't work properly

Description:
------------
Hi , this is really really weird, I think it is a problem with PHP
language, maybe the version PHP5 does not have this problem. Do you
remember that you suggested me to change the Ifs for Switch? I did it, but
for example if song 5 was "vivi.mid", it plays another random song, even
when the result of random is 5. I checked carefully the code and it is
good. The solution is to print the variables, both variables, the one of
case (the one that will have 1, 2, 3, 4, 5) and the one with the value
assigned for each case (example $music=vivi.mid). But if I do not print the
2 variables, it playes something always random but different than the
corresponding case. It is totally crazy, but this is out of my hands to
control, I think it is a problem with PHP language, probably other versions
have improved this. It is weird and crazy. But since you believe that case
will make this faster than If (and I believe that too), I will use Switch,
and I will try to find a way to print the two variables but invisible,
example:

$value = rand(1,51);//Random between 1 to 51 (inclusive).
   switch($value){
      case 1:
         $music = 'pactos.mid';
      break;
      case 2:
         $music = 'otrave.mid';
      break;
}
echo "<embed src='$music' hidden='true' volume='75%'>";

If I don't print both $value and $music with echo, the results are crazy,
because $value takes the value of 1 and $music takes other value, let's say
the song corresponding to $value 40. So, crazy thing, oh well, I will see
how to print the two variables invisible, which solves the problem.

Reproduce code:
---------------
$value = rand(1,51);//Random between 1 to 51 (inclusive).
   switch($value){
      case 1:
         $music = 'pactos.mid';
      break;
      case 2:
         $music = 'otrave.mid';
      break;
}
echo "<embed src='$music' hidden='true' volume='75%'>";

Expected result:
----------------
If $value=1, I would expect to hear pactos.mid song, but I hear a
different one, like the one in case 2, or any other different case.

Actual result:
--------------
If $value=1, I would expect to hear pactos.mid song, but I hear a
different one, like the one in case 2, or any other different case.

-- 
Edit bug report at http://bugs.php.net/?id=43902&edit=1
-- 
Try a CVS snapshot (PHP 4.4): 
http://bugs.php.net/fix.php?id=43902&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): 
http://bugs.php.net/fix.php?id=43902&r=trysnapshot52
Try a CVS snapshot (PHP 5.3): 
http://bugs.php.net/fix.php?id=43902&r=trysnapshot53
Try a CVS snapshot (PHP 6.0): 
http://bugs.php.net/fix.php?id=43902&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=43902&r=fixedcvs
Fixed in release:             
http://bugs.php.net/fix.php?id=43902&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=43902&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=43902&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=43902&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=43902&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=43902&r=notwrong
Not enough info:              
http://bugs.php.net/fix.php?id=43902&r=notenoughinfo
Submitted twice:              
http://bugs.php.net/fix.php?id=43902&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=43902&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=43902&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=43902&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=43902&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=43902&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=43902&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=43902&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=43902&r=mysqlcfg

Reply via email to