ID:               43017
 Updated by:       [EMAIL PROTECTED]
 Reported By:      dharma dot yp at in dot ibm dot com
-Status:           Assigned
+Status:           Closed
 Bug Type:         Arrays related
 Operating System: Windows, Linux
 PHP Version:      5.2CVS-2007-10-18 (snap)
 Assigned To:      jani
 New Comment:

This is now consistent between 5.3 and 6.


Previous Comments:
------------------------------------------------------------------------

[2007-11-01 12:00:41] [EMAIL PROTECTED]

And note: the error message is the expected behaviour. If a function
expects to get an integer as parameter and you pass it something else ->
error.

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

[2007-11-01 10:50:14] [EMAIL PROTECTED]

Soon it will be consistent once I sync HEAD with PHP_5_3. 5.2 will not
be changed though!

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

[2007-10-18 10:51:15] dharma dot yp at in dot ibm dot com

Description:
------------
1) In php 5 when following values are given as value for $start_key,
the values
are not automatically converted and used,A warning message is
displayed. However
automatic conversion of these values happen in php6 and the converted
values are 
used, hence no warning messages generated. 
The $start_key values are : 
    null, NULL, true, false, TRUE, FALSE.

The warning message generated in php5 is :

Warning: array_fill(): Wrong data type for start key in %s on line %d
bool(false)

2) In php6 when empty string("" & '') is given as $start_key the
array_fill() 
function generates an warning however in php5 it doesn't. conversion
happens 
and the value is used.

The warning message generated in php6 is :

Warning: array_fill() expects parameter 1 to be long, string given in
%s on line 3
NULL


Please note that documentation doesn't say any thing in specific for
these but looking at
array type documentation(
http://in.php.net/manual/en/language.types.array.php ), 
an array could have any of these as key. Since this function is doing
the creation of 
an array with specified values, it should create array in all possible
ways, 
that can be created in general using array(). If not, then one would
have to write 
an work-around code when these value are to be passed to array_fill().

Reproduce code:
---------------
1) null and boolean values as $start_key

<?php
var_dump( array_fill(TRUE, 2, 100) );
var_dump( array_fill(NULL, 2, 100) );
?>

2) empty string value as $start_key

<?php
var_dump( array_fill("", 2, 100) );
?>


Expected result:
----------------
1) null and boolean values as $start_key

array(2) {
  [1]=>
  int(100)
  [2]=>
  int(100)
}

array(2) {
  [0]=>
  int(100)
  [1]=>
  int(100)
}

2) empty string value as $start_key

array(2) {
  [0]=>
  int(100)
  [1]=>
  int(100)
}


Actual result:
--------------
1) null and boolean values as $start_key
on php5:
Warning: array_fill(): Wrong data type for start key in %s on line %d
bool(false)


Warning: array_fill(): Wrong data type for start key in %s on line %d
bool(false)

on php6:
array(2) {
  [1]=>
  int(100)
  [2]=>
  int(100)
}

array(2) {
  [0]=>
  int(100)
  [1]=>
  int(100)
}

2) empty string value as $start_key
on php6:

Warning: array_fill() expects parameter 1 to be long, string given in
%s on line %d
NULL

Warning: array_fill() expects parameter 1 to be long, string given in
%s on line %d
NULL


on php5:
array(2) {
  [0]=>
  int(100)
  [1]=>
  int(100)
}





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


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

Reply via email to