# New Ticket Created by "Daniel Keane" # Please include the string: [perl #61800] # in the subject line of all future correspondence about this issue. # <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=61800 >
Implements array_fill() function within pipp. Files affected: * src/common/php_array.pir: added array_fill(), added perldoc comments for array() * src/common/builtins.pir: changed param type for 'prefix:-', was previously converting param to num type and affecting parse_parameter() function in src/common/php_API.pir * src/t/in_php: removed array() function tests and added to new test file * provided new test file for array functions (t/php/array.t) Thanks
Index: t/in_php/array.t
===================================================================
--- t/in_php/array.t (revision 34538)
+++ t/in_php/array.t (working copy)
@@ -27,7 +27,7 @@
require_once 'Test.php';
-plan(11);
+plan(8);
$count = 1;
$hello['world'] = 'hi';
@@ -61,18 +61,5 @@
is( count($thrice), 2, 'count of $thrice', $count );
$count++;
-#test array() function
-
-$arrayfunc = array(0, "key" => "key", 1);
-
-is( $arrayfunc[0], 0, 'arrayfunc[0]', $count );
-$count++;
-is( $arrayfunc[1], 1, 'arrayfunc[1]', $count );
-$count++;
-is( $arrayfunc["key"], 'key', 'arrayfunc[key]', $count );
-$count++;
-
-
-
# vim: expandtab shiftwidth=4 ft=php:
?>
Index: src/common/php_array.pir
===================================================================
--- src/common/php_array.pir (revision 34538)
+++ src/common/php_array.pir (working copy)
@@ -61,6 +61,12 @@
.REGISTER_LONG_CONSTANT(cst, 'COUNT_RECURSIVE', COUNT_RECURSIVE)
.end
+=item C<array array([mixed $...])>
+
+Creates an array
+
+=cut
+
.sub 'array'
.param pmc args :slurpy
.local pmc array, iter
@@ -199,12 +205,34 @@
Create an array containing num elements starting with index start_key each initialized to val
-NOT IMPLEMENTED.
-
=cut
.sub 'array_fill'
- not_implemented()
+ .param pmc args :slurpy
+ .local pmc array, index, value
+ .local int count
+ array = new 'PhpArray'
+ ($I0, index, count, value) = parse_parameters('llz', args :flat)
+ unless $I0 goto L4
+ unless count >= 0 goto L3
+ #set start index then continue from 0
+ unless index < 0 goto L1
+ array[index] = value
+ index = 0
+ $I0 = 1
+ goto L2
+ L1:
+ $I0 = 0
+ L2:
+ inc $I0
+ unless $I0 <= count goto L4
+ array[index] = value
+ inc index
+ goto L2
+ L3:
+ error(E_WARNING, "Warning: array_fill(): Number of elements must be positive")
+ L4:
+ .return(array)
.end
=item C<array array_fill_keys(array keys, mixed val)>
Index: src/common/builtins.pir
===================================================================
--- src/common/builtins.pir (revision 34538)
+++ src/common/builtins.pir (working copy)
@@ -71,7 +71,7 @@
## symbolic unary
.sub 'prefix:-' :multi(_)
- .param num a
+ .param pmc a
neg a
array.t
Description: Troff document
