Hi, 

settype() should be able to handle "boolean" as a target type, but the
docs don't mention this.

<para>
        Possibles values of <parameter>type</parameter> are:
        <itemizedlist>
                <listitem>
                        <simpara>"integer"</simpara>
                </listitem>
                <listitem>
                        <simpara>"double"</simpara>
                </listitem>
                <listitem>
                        <simpara>"string"</simpara>
                </listitem>
                <listitem>
                        <simpara>"array"</simpara>
                </listitem>
                <listitem>
                        <simpara>"object"</simpara>
                </listitem>
        </itemizedlist>
</para>

and ext/standard/basic_functions.c:

PHP_FUNCTION(settype)
{
        pval **var, **type;
        char *new_type;

        if (ZEND_NUM_ARGS() != 2 || zend_get_parameters_ex(2, &var,
&type) ==
FAILURE) {
                WRONG_PARAM_COUNT;
        }
        convert_to_string_ex(type);
        new_type = Z_STRVAL_PP(type);

        if (!strcasecmp(new_type, "integer")) {
                convert_to_long(*var);
        } else if (!strcasecmp(new_type, "double")) {
                convert_to_double(*var);
        } else if (!strcasecmp(new_type, "string")) {
                convert_to_string(*var);
        } else if (!strcasecmp(new_type, "array")) {
                convert_to_array(*var);
        } else if (!strcasecmp(new_type, "object")) {
                convert_to_object(*var);
        } else if (!strcasecmp(new_type, "boolean")) {
                convert_to_boolean(*var);
        } else if (!strcasecmp(new_type, "resource")) {
                php_error(E_WARNING, "settype: cannot convert to
resource type");
                RETURN_FALSE;
        } else {
                php_error(E_WARNING, "settype: invalid type");
                RETURN_FALSE;
        }
        RETVAL_TRUE;
}

        
Ulf

Reply via email to