lstrojny Wed Aug 20 20:35:45 2008 UTC
Added files: (Branch: PHP_5_3)
/php-src/ext/standard/tests/array array_reduce.phpt
Modified files:
/php-src NEWS
/php-src/ext/standard array.c url.c var.c
Log:
MFH: Allow mixed $initial (patch by Christian Seiler)
http://cvs.php.net/viewvc.cgi/php-src/NEWS?r1=1.2027.2.547.2.965.2.282&r2=1.2027.2.547.2.965.2.283&diff_format=u
Index: php-src/NEWS
diff -u php-src/NEWS:1.2027.2.547.2.965.2.282
php-src/NEWS:1.2027.2.547.2.965.2.283
--- php-src/NEWS:1.2027.2.547.2.965.2.282 Wed Aug 20 01:34:51 2008
+++ php-src/NEWS Wed Aug 20 20:35:34 2008
@@ -6,6 +6,7 @@
- Changed session_start() to return false when session startup fails. (Jani)
- Changed property_exists() to check the existence of a property independent of
accessibility (like method_exists()). (Felipe)
+- Changed array_reduce() to allow mixed $initial (Christian Seiler)
- Added system independent realpath() implementation which caches intermediate
directories in realpath-cache. (Dmitry)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/array.c?r1=1.308.2.21.2.37.2.41&r2=1.308.2.21.2.37.2.42&diff_format=u
Index: php-src/ext/standard/array.c
diff -u php-src/ext/standard/array.c:1.308.2.21.2.37.2.41
php-src/ext/standard/array.c:1.308.2.21.2.37.2.42
--- php-src/ext/standard/array.c:1.308.2.21.2.37.2.41 Sun Aug 17 22:14:14 2008
+++ php-src/ext/standard/array.c Wed Aug 20 20:35:34 2008
@@ -21,7 +21,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: array.c,v 1.308.2.21.2.37.2.41 2008/08/17 22:14:14 felipe Exp $ */
+/* $Id: array.c,v 1.308.2.21.2.37.2.42 2008/08/20 20:35:34 lstrojny Exp $ */
#include "php.h"
#include "php_ini.h"
@@ -4067,7 +4067,7 @@
}
/* }}} */
-/* {{{ proto mixed array_reduce(array input, mixed callback [, int initial])
+/* {{{ proto mixed array_reduce(array input, mixed callback [, mixed initial])
Iteratively reduce the array to a single value via the callback. */
PHP_FUNCTION(array_reduce)
{
@@ -4078,18 +4078,19 @@
zval *retval;
zend_fcall_info fci;
zend_fcall_info_cache fci_cache = empty_fcall_info_cache;
- long initial;
+ zval *initial;
HashPosition pos;
HashTable *htbl;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "af|l", &input,
&fci, &fci_cache, &initial) == FAILURE) {
+ if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "af|z", &input,
&fci, &fci_cache, &initial) == FAILURE) {
return;
}
if (ZEND_NUM_ARGS() > 2) {
ALLOC_ZVAL(result);
+ *result = *initial;
+ zval_copy_ctor(result);
INIT_PZVAL(result);
- ZVAL_LONG(result, initial);
} else {
MAKE_STD_ZVAL(result);
ZVAL_NULL(result);
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/url.c?r1=1.86.2.5.2.7.2.4&r2=1.86.2.5.2.7.2.5&diff_format=u
Index: php-src/ext/standard/url.c
diff -u php-src/ext/standard/url.c:1.86.2.5.2.7.2.4
php-src/ext/standard/url.c:1.86.2.5.2.7.2.5
--- php-src/ext/standard/url.c:1.86.2.5.2.7.2.4 Wed Jun 4 19:35:15 2008
+++ php-src/ext/standard/url.c Wed Aug 20 20:35:39 2008
@@ -15,7 +15,7 @@
| Author: Jim Winstead <[EMAIL PROTECTED]>
|
+----------------------------------------------------------------------+
*/
-/* $Id: url.c,v 1.86.2.5.2.7.2.4 2008/06/04 19:35:15 rrichards Exp $ */
+/* $Id: url.c,v 1.86.2.5.2.7.2.5 2008/08/20 20:35:39 lstrojny Exp $ */
#include <stdlib.h>
#include <string.h>
@@ -65,21 +65,23 @@
{
unsigned char *s = (unsigned char *)str;
unsigned char *e = (unsigned char *)str + len;
-
+ unsigned char *r[len + 1];
+ unsigned int c = 0;
+
if (!str) {
- return (NULL);
+ return NULL;
}
-
+
while (s < e) {
-
- if (iscntrl(*s)) {
- *s='_';
- }
+ if (0 == iscntrl(*s)) {
+ r[c] = *s;
+ c++;
+ }
s++;
}
-
- return (str);
-}
+
+ return (unsigned char *)r;
+}
/* }}} */
PHPAPI char *php_replace_controlchars(char *str)
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/var.c?r1=1.203.2.7.2.18.2.10&r2=1.203.2.7.2.18.2.11&diff_format=u
Index: php-src/ext/standard/var.c
diff -u php-src/ext/standard/var.c:1.203.2.7.2.18.2.10
php-src/ext/standard/var.c:1.203.2.7.2.18.2.11
--- php-src/ext/standard/var.c:1.203.2.7.2.18.2.10 Thu Jul 24 19:52:24 2008
+++ php-src/ext/standard/var.c Wed Aug 20 20:35:40 2008
@@ -18,7 +18,7 @@
+----------------------------------------------------------------------+
*/
-/* $Id: var.c,v 1.203.2.7.2.18.2.10 2008/07/24 19:52:24 felipe Exp $ */
+/* $Id: var.c,v 1.203.2.7.2.18.2.11 2008/08/20 20:35:40 lstrojny Exp $ */
/* {{{ includes
*/
@@ -422,7 +422,7 @@
php_printf("\n%*c", level - 1, ' ');
}
Z_OBJ_HANDLER(**struc, get_class_name)(*struc, &class_name,
&class_name_len, 0 TSRMLS_CC);
- php_printf ("%s::__set_state(array(\n", class_name);
+ php_printf ("%s::__setState(array(\n", class_name);
efree(class_name);
if (myht) {
zend_hash_apply_with_arguments(myht TSRMLS_CC,
(apply_func_args_t) php_object_element_export, 1, level);
http://cvs.php.net/viewvc.cgi/php-src/ext/standard/tests/array/array_reduce.phpt?view=markup&rev=1.1
Index: php-src/ext/standard/tests/array/array_reduce.phpt
+++ php-src/ext/standard/tests/array/array_reduce.phpt
--TEST--
Test array_reduce() function
--INI--
precision=14
--FILE--
<?php
/* Prototype: array array_reduce(array $array, mixed $callback, mixed $initial);
Description: Iteratively reduce the array to a single value via the callback
*/
$array = array('foo', 'foo', 'bar', 'qux', 'qux', 'quux');
echo "\n*** Testing array_reduce() to integer ***\n";
function reduce_int($w, $v) { return $w + strlen($v); }
$initial = 42;
var_dump(array_reduce($array, 'reduce_int', $initial), $initial);
echo "\n*** Testing array_reduce() to float ***\n";
function reduce_float($w, $v) { return $w + strlen($v) / 10; }
$initial = 4.2;
var_dump(array_reduce($array, 'reduce_float', $initial), $initial);
echo "\n*** Testing array_reduce() to string ***\n";
function reduce_string($w, $v) { return $w . $v; }
$initial = 'quux';
var_dump(array_reduce($array, 'reduce_string', $initial), $initial);
echo "\n*** Testing array_reduce() to array ***\n";
function reduce_array($w, $v) { $w[$v]++; return $w; }
$initial = array('foo' => 42, 'bar' => 17, 'qux' => -2, 'quux' => 0);
var_dump(array_reduce($array, 'reduce_array', $initial), $initial);
echo "\n*** Testing array_reduce() to null ***\n";
function reduce_null($w, $v) { return $w . $v; }
$initial = null;
var_dump(array_reduce($array, 'reduce_null', $initial), $initial);
echo "\nDone";
?>
--EXPECTF--
*** Testing array_reduce() to integer ***
int(61)
int(42)
*** Testing array_reduce() to float ***
float(6.1)
float(4.2)
*** Testing array_reduce() to string ***
unicode(23) "quuxfoofoobarquxquxquux"
unicode(4) "quux"
*** Testing array_reduce() to array ***
array(4) {
[u"foo"]=>
int(44)
[u"bar"]=>
int(18)
[u"qux"]=>
int(0)
[u"quux"]=>
int(1)
}
array(4) {
[u"foo"]=>
int(42)
[u"bar"]=>
int(17)
[u"qux"]=>
int(-2)
[u"quux"]=>
int(0)
}
*** Testing array_reduce() to null ***
unicode(19) "foofoobarquxquxquux"
NULL
Done
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php