From:             tor...@php.net
Operating system: *
PHP version:      5.3SVN-2009-09-08 (SVN)
PHP Bug Type:     Feature/Change Request
Bug description:  xmlrpc_is_fault() should not throw a Notice when given 
argument is not an array

Description:
------------
In bug #40793 and doc bug #49378 it is reported that xmlrpc_is_fault()
throws a Notice when the passed argument is not an array. In the comments
for #40793 tony2...@php.net states that this is by design, and indeed it
appears to be, but that would seem to be a broken design. xmlrpc_is_fault()
should simply return true if the passed argument represents an xmlrpc
fault, and false otherwise.

Patch for PHP 5.2:

Index: ext/xmlrpc/xmlrpc-epi-php.c
===================================================================
--- ext/xmlrpc/xmlrpc-epi-php.c (revision 287478)
+++ ext/xmlrpc/xmlrpc-epi-php.c (working copy)
@@ -1445,7 +1445,7 @@
 /* }}} */
 
 /* {{{ proto bool xmlrpc_is_fault(array)
-   Determines if an array value represents an XMLRPC fault. */
+   Determines if the passed value represents an XMLRPC fault. */
 PHP_FUNCTION(xmlrpc_is_fault)
 {
        zval **arg, **val;
@@ -1455,20 +1455,20 @@
        }
 
        if (Z_TYPE_PP(arg) != IS_ARRAY) {
-               php_error_docref(NULL TSRMLS_CC, E_NOTICE, "Array argument 
expected");
-       } else {
-               /* The "correct" way to do this would be to call the xmlrpc
-                * library XMLRPC_ValueIsFault() func.  However, doing that
-                * would require us to create an xmlrpc value from the php
-                * array, which is rather expensive, especially if it was
-                * a big array.  Thus, we resort to this not so clever hackery.
-                */
-               if (zend_hash_find(Z_ARRVAL_PP(arg), FAULT_CODE, FAULT_CODE_LEN 
+ 1,
(void**) &val) == SUCCESS && 
-                   zend_hash_find(Z_ARRVAL_PP(arg), FAULT_STRING, 
FAULT_STRING_LEN +
1, (void**) &val) == SUCCESS) {
-                       RETURN_TRUE;
-               }
+               RETURN_FALSE;
        }
 
+       /* The "correct" way to do this would be to call the xmlrpc
+        * library XMLRPC_ValueIsFault() func.  However, doing that
+        * would require us to create an xmlrpc value from the php
+        * array, which is rather expensive, especially if it was
+        * a big array.  Thus, we resort to this not so clever hackery.
+        */
+       if (zend_hash_find(Z_ARRVAL_PP(arg), FAULT_CODE, FAULT_CODE_LEN + 1,
(void**) &val) == SUCCESS && 
+           zend_hash_find(Z_ARRVAL_PP(arg), FAULT_STRING, FAULT_STRING_LEN + 1,
(void**) &val) == SUCCESS) {
+               RETURN_TRUE;
+       }
+
        RETURN_FALSE;
 }
 /* }}} */


Patch for PHP 5.3:

Index: ext/xmlrpc/xmlrpc-epi-php.c
===================================================================
--- ext/xmlrpc/xmlrpc-epi-php.c (revision 287473)
+++ ext/xmlrpc/xmlrpc-epi-php.c (working copy)
@@ -1495,20 +1495,24 @@
    Determines if an array value represents an XMLRPC fault. */
 PHP_FUNCTION(xmlrpc_is_fault)
 {
-       zval *arg, **val;
+       zval **arg, **val;
 
-       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "a", &arg) ==
FAILURE) {
+       if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "Z", &arg) ==
FAILURE) {
                return;
        }
 
+       if (Z_TYPE_PP(arg) != IS_ARRAY) {
+               RETURN_FALSE;
+       }
+
        /* The "correct" way to do this would be to call the xmlrpc
         * library XMLRPC_ValueIsFault() func.  However, doing that
         * would require us to create an xmlrpc value from the php
         * array, which is rather expensive, especially if it was
         * a big array.  Thus, we resort to this not so clever hackery.
         */
-       if (zend_hash_find(Z_ARRVAL_P(arg), FAULT_CODE, FAULT_CODE_LEN + 1,
(void**) &val) == SUCCESS && 
-               zend_hash_find(Z_ARRVAL_P(arg), FAULT_STRING, FAULT_STRING_LEN 
+ 1,
(void**) &val) == SUCCESS) {
+       if (zend_hash_find(Z_ARRVAL_PP(arg), FAULT_CODE, FAULT_CODE_LEN + 1,
(void**) &val) == SUCCESS && 
+               zend_hash_find(Z_ARRVAL_PP(arg), FAULT_STRING, FAULT_STRING_LEN 
+ 1,
(void**) &val) == SUCCESS) {
                RETURN_TRUE;
        }
 



-- 
Edit bug report at http://bugs.php.net/?id=49496&edit=1
-- 
Try a snapshot (PHP 5.2):            
http://bugs.php.net/fix.php?id=49496&r=trysnapshot52
Try a snapshot (PHP 5.3):            
http://bugs.php.net/fix.php?id=49496&r=trysnapshot53
Try a snapshot (PHP 6.0):            
http://bugs.php.net/fix.php?id=49496&r=trysnapshot60
Fixed in SVN:                        
http://bugs.php.net/fix.php?id=49496&r=fixed
Fixed in SVN and need be documented: 
http://bugs.php.net/fix.php?id=49496&r=needdocs
Fixed in release:                    
http://bugs.php.net/fix.php?id=49496&r=alreadyfixed
Need backtrace:                      
http://bugs.php.net/fix.php?id=49496&r=needtrace
Need Reproduce Script:               
http://bugs.php.net/fix.php?id=49496&r=needscript
Try newer version:                   
http://bugs.php.net/fix.php?id=49496&r=oldversion
Not developer issue:                 
http://bugs.php.net/fix.php?id=49496&r=support
Expected behavior:                   
http://bugs.php.net/fix.php?id=49496&r=notwrong
Not enough info:                     
http://bugs.php.net/fix.php?id=49496&r=notenoughinfo
Submitted twice:                     
http://bugs.php.net/fix.php?id=49496&r=submittedtwice
register_globals:                    
http://bugs.php.net/fix.php?id=49496&r=globals
PHP 4 support discontinued:          http://bugs.php.net/fix.php?id=49496&r=php4
Daylight Savings:                    http://bugs.php.net/fix.php?id=49496&r=dst
IIS Stability:                       
http://bugs.php.net/fix.php?id=49496&r=isapi
Install GNU Sed:                     
http://bugs.php.net/fix.php?id=49496&r=gnused
Floating point limitations:          
http://bugs.php.net/fix.php?id=49496&r=float
No Zend Extensions:                  
http://bugs.php.net/fix.php?id=49496&r=nozend
MySQL Configuration Error:           
http://bugs.php.net/fix.php?id=49496&r=mysqlcfg

Reply via email to