xmlrpcval::addScalar PHP Méthode

addScalar() public méthode

public addScalar ( $val, $type = "string" )
    function addScalar($val, $type = "string")
    {
        global $xmlrpcTypes, $xmlrpcBoolean;
        if ($this->mytype == 1) {
            echo "<B>xmlrpcval</B>: scalar can have only one value<BR>";
            return 0;
        }
        $typeof = $xmlrpcTypes[$type];
        if ($typeof != 1) {
            echo "<B>xmlrpcval</B>: not a scalar type ({$typeof})<BR>";
            return 0;
        }
        if ($type == $xmlrpcBoolean) {
            if (strcasecmp($val, "true") == 0 || $val == 1 || $val == true && strcasecmp($val, "false")) {
                $val = 1;
            } else {
                $val = 0;
            }
        }
        if ($this->mytype == 2) {
            // we're adding to an array here
            $ar = $this->me["array"];
            $ar[] = new xmlrpcval($val, $type);
            $this->me["array"] = $ar;
        } else {
            // a scalar, so set the value and remember we're scalar
            $this->me[$type] = $val;
            $this->mytype = $typeof;
        }
        return 1;
    }

Usage Example

Exemple #1
0
function xmlrpc_encode($php_val)
{
    global $xmlrpcInt;
    global $xmlrpcDouble;
    global $xmlrpcString;
    global $xmlrpcArray;
    global $xmlrpcStruct;
    global $xmlrpcBoolean;
    $type = gettype($php_val);
    $xmlrpc_val = new xmlrpcval();
    switch ($type) {
        case "array":
        case "object":
            $arr = array();
            while (list($k, $v) = each($php_val)) {
                $arr[$k] = xmlrpc_encode($v);
            }
            $xmlrpc_val->addStruct($arr);
            break;
        case "integer":
            $xmlrpc_val->addScalar($php_val, $xmlrpcInt);
            break;
        case "double":
            $xmlrpc_val->addScalar($php_val, $xmlrpcDouble);
            break;
        case "string":
            $xmlrpc_val->addScalar($php_val, $xmlrpcString);
            break;
            // <G_Giunta_2001-02-29>
            // Add support for encoding/decoding of booleans, since they are supported in PHP
        // <G_Giunta_2001-02-29>
        // Add support for encoding/decoding of booleans, since they are supported in PHP
        case "boolean":
            $xmlrpc_val->addScalar($php_val, $xmlrpcBoolean);
            break;
            // </G_Giunta_2001-02-29>
        // </G_Giunta_2001-02-29>
        case "unknown type":
        default:
            // giancarlo pinerolo <*****@*****.**>
            // it has to return
            // an empty object in case (which is already
            // at this point), not a boolean.
            break;
    }
    return $xmlrpc_val;
}
All Usage Examples Of xmlrpcval::addScalar