[PHP-DEV] RC5 hexdec not compatible

2001-12-04 Thread chrism

?php /* hexdec.php */

/* 4.1.0 branch hexdec not compatible
 * with earlier PHP releases.
 */

/*

% php4.0.0 -f hexdec.php
lemon = 5d08374e = 1560819534
pineapple = a7e9b7d0 = -1477855280
fruit = c10d50e3 = -1056091933
sausage = 42d08254 = 1120961108
breakfast = f7d7b86e = -136857490
coconut = 1138ca81 = 288934529

% php4.0.6 -f hexdec.php
lemon = 5d08374e = 1560819534
pineapple = a7e9b7d0 = -1477855280
fruit = c10d50e3 = -1056091933
sausage = 42d08254 = 1120961108
breakfast = f7d7b86e = -136857490
coconut = 1138ca81 = 288934529

% php4.1.0RC5 -f hexdec.php
lemon = 5d08374e = 1560819534
pineapple = a7e9b7d0 = 2817112016
fruit = c10d50e3 = 3238875363
sausage = 42d08254 = 1120961108
breakfast = f7d7b86e = 4158109806
coconut = 1138ca81 = 288934529

*/

$wordlist = array(lemon, pineapple, fruit, sausage,
  breakfast,coconut);

foreach($wordlist as $word) {
$crc = mhash(MHASH_CRC32, $word);
$hex = bin2hex($crc);
$dec = hexdec($hex);
echo $word .  =  . $hex .  =  . $dec . \n;
}

?

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DEV] switch, equality and preg_match

2001-07-01 Thread chrism

I wasn't intending to throw blame at preg_match - My main concern is what
switch is doing - executing the first CASE when the input is either 0 or
TRUE.

I don't think switch should execute the first CASE whenever a numeric 0 is
fed into it.

Even TRUE gives me problems.  And with 0 == FALSE, it all seems so messed up.

Chris

 
 Here is your culprit:
 
  RETVAL_LONG(matched);
 
 The declaration in the docs says the function returns an int.  However, the
 text of the doc says that the function returns True or False.
 
 Changing your call to:
 
 $match = (bool)preg_false(); /* prints alpha always */
 
 gives you the results you want.
 
 Andrei, you are listed as the author on this file.  What needs to change?
 The return type?  That would make the most sense to me.
 
 Brian Moon
 --
 dealnews.com, Inc.
 Makers of dealnews, dealmac
 http://dealnews.com/ | http://dealmac.com/
 
 
 - Original Message -
 From: chrism [EMAIL PROTECTED]
 To: [EMAIL PROTECTED]
 Sent: Saturday, June 30, 2001 7:02 PM
 Subject: [PHP-DEV] switch, equality and preg_match
 
 
  I encountered a problem where the result of a preg_match was FALSE.
  This was fed into a switch statement - and I believe PHP executed the
  the wrong case section.
 
  I've tracked this down to preg_match not really returning FALSE
  combined with SWITCH executing the first case statement always on either
  a numeric 0 or BOOLEAN TRUE.
 
  As a consequence of auto type conversion, you can't mix
  STRING/NUMERIC/BOOLEAN within a switch.  And with the preg_match issue,
  you can't assume all input into your switch will be of one TYPE (BOOLEAN).
 
  Aside from changing functions to return real booleans
 
  1. Should type conversion be turned off inside switch() ?
  2. If 0 == FALSE then why 0 == ANYTHING ?
 
  Chris
 
  ?
 
  /* auto type conversion is the root of my switch problem */
 
  if (0 == ONE) echo one\n; /* TRUE */
  if (1 == TWO) echo two\n; /* FALSE */
  if (TRUE == THREE) echo three\n; /* TRUE */
  if (FALSE == FOUR) echo four\n; /* FALSE */
 
  if (TRUE == 0) echo hopefully not\n;
 
  function preg_false() {
  return(preg_match(/no/, dXiuehXX));
  }
 
  /* note the difference between FALSE and preg_false() */
 
  // $match = TRUE; /* prints alpha always */
  // $match = 0; /* prints alpha always */
  // $match = FALSE; /* prints gamma section */
  $match = preg_false(); /* prints alpha always */
 
  if(is_bool($match) == TRUE)  echo match is boolean\n;
 
  switch($match) {
  case ALPHA:
  echo hmm.. alpha\n;
  break;
  case BETA:
  echo hmm.. beta\n;
  break;
  case 0:
  echo hmm.. gamma\n;
  break;
  case TRUE:
  echo hmm.. TRUE\n;
  break;
  case FALSE:
  echo hmm.. FALSE\n;
  break;
  }
 
  ?
 
  --
  PHP Development Mailing List http://www.php.net/
  To unsubscribe, e-mail: [EMAIL PROTECTED]
  For additional commands, e-mail: [EMAIL PROTECTED]
  To contact the list administrators, e-mail: [EMAIL PROTECTED]
 
 
 
 
 


-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] no subject (file transmission)

2001-06-30 Thread chrism

I encountered a problem where the result of a preg_replace was FALSE.
This was fed into a switch statement - and I believe PHP executed the
the wrong case section.

I've tracked this down to preg_replace not really returning FALSE
combined with SWITCH executing the first case statement always on either
a numeric 0 or BOOLEAN TRUE.

As a consequence of auto type conversion, you can't mix
STRING/NUMERIC/BOOLEAN within a switch.  And with the preg_replace issue,
you can't assume all input into your switch will be of one TYPE (BOOLEAN).

Aside from changing functions to return real booleans

1. Should type conversion be turned off inside switch() ?
2. If 0 == FALSE then why 0 == ANYTHING ?

Chris

?

/* auto type conversion is the root of my switch problem */

if (0 == ONE) echo one\n;   /* TRUE */
if (1 == TWO) echo two\n;   /* FALSE */
if (TRUE == THREE) echo three\n;/* TRUE */
if (FALSE == FOUR) echo four\n; /* FALSE */

if (TRUE == 0) echo hopefully not\n;

function preg_false() {
return(preg_match(/no/, dXiuehXX));
}

/* note the difference between FALSE and preg_false() */

// $match = TRUE;   /* prints alpha always */
// $match = 0;  /* prints alpha always */
// $match = FALSE;  /* prints gamma section */
$match = preg_false();  /* prints alpha always */

if(is_bool($match) == TRUE)  echo match is boolean\n;

switch($match) {
case ALPHA:
echo hmm.. alpha\n;
break;
case BETA:
echo hmm.. beta\n;
break;
case 0:
echo hmm.. gamma\n;
break;
case TRUE:
echo hmm.. TRUE\n;
break;
case FALSE:
echo hmm.. FALSE\n;
break;
}

?

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP-DEV] switch, equality and preg_match

2001-06-30 Thread chrism

I encountered a problem where the result of a preg_match was FALSE.
This was fed into a switch statement - and I believe PHP executed the
the wrong case section.

I've tracked this down to preg_match not really returning FALSE
combined with SWITCH executing the first case statement always on either
a numeric 0 or BOOLEAN TRUE.

As a consequence of auto type conversion, you can't mix
STRING/NUMERIC/BOOLEAN within a switch.  And with the preg_match issue,
you can't assume all input into your switch will be of one TYPE (BOOLEAN).

Aside from changing functions to return real booleans

1. Should type conversion be turned off inside switch() ?
2. If 0 == FALSE then why 0 == ANYTHING ?

Chris

?

/* auto type conversion is the root of my switch problem */

if (0 == ONE) echo one\n;   /* TRUE */
if (1 == TWO) echo two\n;   /* FALSE */
if (TRUE == THREE) echo three\n;/* TRUE */
if (FALSE == FOUR) echo four\n; /* FALSE */

if (TRUE == 0) echo hopefully not\n;

function preg_false() {
return(preg_match(/no/, dXiuehXX));
}

/* note the difference between FALSE and preg_false() */

// $match = TRUE;   /* prints alpha always */
// $match = 0;  /* prints alpha always */
// $match = FALSE;  /* prints gamma section */
$match = preg_false();  /* prints alpha always */

if(is_bool($match) == TRUE)  echo match is boolean\n;

switch($match) {
case ALPHA:
echo hmm.. alpha\n;
break;
case BETA:
echo hmm.. beta\n;
break;
case 0:
echo hmm.. gamma\n;
break;
case TRUE:
echo hmm.. TRUE\n;
break;
case FALSE:
echo hmm.. FALSE\n;
break;
}

?

-- 
PHP Development Mailing List http://www.php.net/
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]