#21918 [Ver]: strange behaviour of mixed type in array-keys

2003-02-08 Thread moriyoshi
 ID:   21918
 Updated by:   [EMAIL PROTECTED]
 Reported By:  [EMAIL PROTECTED]
 Status:   Verified
 Bug Type: Scripting Engine problem
 Operating System: Linux
 PHP Version:  4.3.0/5.0.0
 New Comment:

Related to bug #8325



Previous Comments:


[2003-01-29 02:22:57] [EMAIL PROTECTED]

I relied on http://www.php.net/manual/en/language.types.array.php

it states:

A key is either an integer or a string. If a key is the standard
representation of an integer, it will be interpreted as such (i.e. 8
will be interpreted as 8, while 08 will be interpreted as 08).

so the keys should be casted to int, or it is a documentation-bug, or
-1 is not a standard representation of an integer.



[2003-01-29 00:57:01] [EMAIL PROTECTED]

?php

$a = array(
 '-1' = '-1',
  '0' = '0',
  '1' = '1',
);

var_dump($a);

?

Output:

array(3) {
  [-1]=
  string(2) -1
  [0]=
  string(1) 0
  [1]=
  string(1) 1
}

(the '0' and '1' indexes are converted to integers..)
Not sure if this is actually expected behaviour. :)




[2003-01-29 00:39:34] [EMAIL PROTECTED]

The bug can be that it shouldn't cast positive numbers to string and
not that it should cast negative numbers to string.



[2003-01-29 00:31:41] [EMAIL PROTECTED]

Verified under PHP 4.3.0 with Zend Engine v1.3.0 and PHP 5.0.0-dev with
Zend Engine v2.0.0-dev.

It looks like '-1' isn't casted to int as it should.





[2003-01-28 04:58:13] [EMAIL PROTECTED]

?php

$a = array(-1=1,
   '-1'=2,
   0=3,
   '0'=4,
   1=5,
   '1'=6
   );

print_r($a);

?

produces:
Array
(
[-1] = 1
[-1] = 2
[0] = 4
[1] = 6
)


foreach (array_keys($a) as $key) echo $key, ': ', gettype($key), \n;
produces:
-1: integer
-1: string
0: integer
1: integer

so it seems strings containing negative integers do not get converted
to
integers automagically but positive integers are.






-- 
Edit this bug report at http://bugs.php.net/?id=21918edit=1




#21918 [Ver]: strange behaviour of mixed type in array-keys

2003-01-28 Thread nicos
 ID:   21918
 Updated by:   [EMAIL PROTECTED]
 Reported By:  [EMAIL PROTECTED]
 Status:   Verified
 Bug Type: Arrays related
 Operating System: Linux
 PHP Version:  4.3.0/5.0.0
 New Comment:

The bug can be that it shouldn't cast positive numbers to string and
not that it should cast negative numbers to string.


Previous Comments:


[2003-01-29 00:31:41] [EMAIL PROTECTED]

Verified under PHP 4.3.0 with Zend Engine v1.3.0 and PHP 5.0.0-dev with
Zend Engine v2.0.0-dev.

It looks like '-1' isn't casted to int as it should.





[2003-01-28 04:58:13] [EMAIL PROTECTED]

?php

$a = array(-1=1,
   '-1'=2,
   0=3,
   '0'=4,
   1=5,
   '1'=6
   );

print_r($a);

?

produces:
Array
(
[-1] = 1
[-1] = 2
[0] = 4
[1] = 6
)


foreach (array_keys($a) as $key) echo $key, ': ', gettype($key), \n;
produces:
-1: integer
-1: string
0: integer
1: integer

so it seems strings containing negative integers do not get converted
to
integers automagically but positive integers are.






-- 
Edit this bug report at http://bugs.php.net/?id=21918edit=1




#21918 [Ver]: strange behaviour of mixed type in array-keys

2003-01-28 Thread sniper
 ID:   21918
 Updated by:   [EMAIL PROTECTED]
 Reported By:  [EMAIL PROTECTED]
 Status:   Verified
 Bug Type: Arrays related
 Operating System: Linux
 PHP Version:  4.3.0/5.0.0
 New Comment:

?php

$a = array(
 '-1' = '-1',
  '0' = '0',
  '1' = '1',
);

var_dump($a);

?

Output:

array(3) {
  [-1]=
  string(2) -1
  [0]=
  string(1) 0
  [1]=
  string(1) 1
}

(the '0' and '1' indexes are converted to integers..)
Not sure if this is actually expected behaviour. :)



Previous Comments:


[2003-01-29 00:39:34] [EMAIL PROTECTED]

The bug can be that it shouldn't cast positive numbers to string and
not that it should cast negative numbers to string.



[2003-01-29 00:31:41] [EMAIL PROTECTED]

Verified under PHP 4.3.0 with Zend Engine v1.3.0 and PHP 5.0.0-dev with
Zend Engine v2.0.0-dev.

It looks like '-1' isn't casted to int as it should.





[2003-01-28 04:58:13] [EMAIL PROTECTED]

?php

$a = array(-1=1,
   '-1'=2,
   0=3,
   '0'=4,
   1=5,
   '1'=6
   );

print_r($a);

?

produces:
Array
(
[-1] = 1
[-1] = 2
[0] = 4
[1] = 6
)


foreach (array_keys($a) as $key) echo $key, ': ', gettype($key), \n;
produces:
-1: integer
-1: string
0: integer
1: integer

so it seems strings containing negative integers do not get converted
to
integers automagically but positive integers are.






-- 
Edit this bug report at http://bugs.php.net/?id=21918edit=1