Why can't we use zend_parse_parameters() here?
-Andrei
On Aug 17, 2005, at 4:36 AM, Dmitry Stogov wrote:
dmitry Wed Aug 17 07:36:32 2005 EDT
Modified files:
/php-src/ext/simplexml/tests 004.phpt
/php-src/ext/standard string.c
/php-src/tests/classes tostring.phpt
/php-src/tests/reflection 005.phpt
Log:
trim() should accept objects with __toString() method
http://cvs.php.net/diff.php/php-src/ext/simplexml/tests/004.phpt?
r1=1.6&r2=1.7&ty=u
Index: php-src/ext/simplexml/tests/004.phpt
diff -u php-src/ext/simplexml/tests/004.phpt:1.6 php-src/ext/
simplexml/tests/004.phpt:1.7
--- php-src/ext/simplexml/tests/004.phpt:1.6 Mon Mar 29 14:58:01
2004
+++ php-src/ext/simplexml/tests/004.phpt Wed Aug 17 07:36:28 2005
@@ -63,3 +63,33 @@
)
string(11) "CDATA block"
===DONE===
+--UEXPECT--
+SimpleXMLElement Object
+(
+ [elem1] => SimpleXMLElement Object
+ (
+ [comment] => SimpleXMLElement Object
+ (
+ )
+
+ [elem2] => SimpleXMLElement Object
+ (
+ [elem3] => SimpleXMLElement Object
+ (
+ [elem4] => SimpleXMLElement Object
+ (
+ [test] => SimpleXMLElement Object
+ (
+ )
+
+ )
+
+ )
+
+ )
+
+ )
+
+)
+unicode(11) "CDATA block"
+===DONE===
http://cvs.php.net/diff.php/php-src/ext/standard/string.c?
r1=1.460&r2=1.461&ty=u
Index: php-src/ext/standard/string.c
diff -u php-src/ext/standard/string.c:1.460 php-src/ext/standard/
string.c:1.461
--- php-src/ext/standard/string.c:1.460 Wed Aug 17 06:26:02 2005
+++ php-src/ext/standard/string.c Wed Aug 17 07:36:30 2005
@@ -18,7 +18,7 @@
+---------------------------------------------------------------------
-+
*/
-/* $Id: string.c,v 1.460 2005/08/17 10:26:02 rolland Exp $ */
+/* $Id: string.c,v 1.461 2005/08/17 11:36:30 dmitry Exp $ */
/* Synced with php 3.0 revision 1.193 1999-06-16 [ssb] */
@@ -737,30 +737,31 @@
*/
static void php_do_trim(INTERNAL_FUNCTION_PARAMETERS, int mode)
{
- void *str;
- int32_t str_len;
- zend_uchar str_type;
- void *what;
- int32_t what_len;
- zend_uchar what_type;
- int argc = ZEND_NUM_ARGS();
+ zval **str, **what;
+ int argc = ZEND_NUM_ARGS();
- if ( zend_parse_parameters(argc TSRMLS_CC, "T|T", &str,
&str_len, &str_type,
- &what, &what_len, &what_type) ==
FAILURE ) {
- return;
+ if (argc < 1 || argc > 2 || zend_get_parameters_ex(argc, &str,
&what) == FAILURE) {
+ WRONG_PARAM_COUNT;
}
- if ( argc > 1 ) {
- if ( str_type == IS_UNICODE ) {
- php_u_trim(str, str_len, what, what_len, return_value,
mode TSRMLS_CC);
+ convert_to_text_ex(str);
+
+ if (argc > 1) {
+ if (Z_TYPE_PP(str) != Z_TYPE_PP(what)) {
+ zend_error(E_WARNING, "%v() expects parameter 2 to be
string (legacy, Unicode, or binary), %s given",
+ get_active_function_name(TSRMLS_C),
+ zend_zval_type_name(*what));
+ }
+ if (Z_TYPE_PP(str) == IS_UNICODE) {
+ php_u_trim(Z_USTRVAL_PP(str), Z_USTRLEN_PP(str),
Z_USTRVAL_PP(what), Z_USTRLEN_PP(what), return_value, mode TSRMLS_CC);
} else {
- php_trim(str, str_len, what, what_len, str_type,
return_value, mode TSRMLS_CC);
+ php_trim(Z_STRVAL_PP(str), Z_STRLEN_PP(str),
Z_STRVAL_PP(what), Z_STRLEN_PP(what), Z_TYPE_PP(str), return_value,
mode TSRMLS_CC);
}
} else {
- if ( str_type == IS_UNICODE ) {
- php_u_trim(str, str_len, NULL, 0, return_value, mode
TSRMLS_CC);
+ if (Z_TYPE_PP(str) == IS_UNICODE) {
+ php_u_trim(Z_USTRVAL_PP(str), Z_USTRLEN_PP(str), NULL,
0, return_value, mode TSRMLS_CC);
} else {
- php_trim(str, str_len, NULL, 0, str_type,
return_value, mode TSRMLS_CC);
+ php_trim(Z_STRVAL_PP(str), Z_STRLEN_PP(str), NULL, 0,
Z_TYPE_PP(str), return_value, mode TSRMLS_CC);
}
}
}
http://cvs.php.net/diff.php/php-src/tests/classes/tostring.phpt?
r1=1.5&r2=1.6&ty=u
Index: php-src/tests/classes/tostring.phpt
diff -u php-src/tests/classes/tostring.phpt:1.5 php-src/tests/
classes/tostring.phpt:1.6
--- php-src/tests/classes/tostring.phpt:1.5 Sun Mar 28 09:09:47
2004
+++ php-src/tests/classes/tostring.phpt Wed Aug 17 07:36:32 2005
@@ -84,3 +84,36 @@
string(1%d) "Object id #%d"
====test9====
Object id #%d====DONE!====
+--UEXPECTF--
+====test1====
+test1 Object
+(
+)
+string(1%d) "Object id #%d"
+object(test1)#%d (%d) {
+}
+====test2====
+test2 Object
+(
+)
+test2::__toString()
+Converted
+object(test2)#%d (%d) {
+}
+====test3====
+test2::__toString()
+Converted
+====test4====
+string:Object id #%d====test5====
+1Object id #%d====test6====
+Object id #%dObject id #2====test7====
+test2::__toString()
+
+Warning: Illegal offset type in %stostring.php on line %d
+====test8====
+
+Notice: Object of class test2 to string conversion in %
stostring.php on line %d
+unicode(6) "Object"
+unicode(1%d) "Object id #%d"
+====test9====
+Object id #%d====DONE!====
http://cvs.php.net/diff.php/php-src/tests/reflection/005.phpt?
r1=1.1&r2=1.2&ty=u
Index: php-src/tests/reflection/005.phpt
diff -u php-src/tests/reflection/005.phpt:1.1 php-src/tests/
reflection/005.phpt:1.2
--- php-src/tests/reflection/005.phpt:1.1 Sun Feb 13 08:50:30 2005
+++ php-src/tests/reflection/005.phpt Wed Aug 17 07:36:32 2005
@@ -52,3 +52,10 @@
bool(false)
string(22) "* Comment for A::baz()"
===DONE===
+--UEXPECT--
+unicode(19) "Comment for class A"
+unicode(15) "Method A::bla()"
+bool(false)
+bool(false)
+unicode(22) "* Comment for A::baz()"
+===DONE===
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php