Re: [PHP4BETA] getParametersEx again....

From: Date: Tue, 14 Sep 1999 16:11:09 +0000
Subject: Re: [PHP4BETA] getParametersEx again....
References: 1  Groups: php.version4 
Request: Send a blank email to php-version4+get-4439@lists.php.net to get a copy of this message
At 14:58 14/09/1999 , Thies C. Arntzen wrote:
just playing around.... PHP_FUNCTION(count) {
    pval **array;
    HashTable *target_hash;
    if (ARG_COUNT(ht) != 1 || getParametersEx(1, &array) == FAILURE) {
        WRONG_PARAM_COUNT;
    }
    target_hash = HASH_OF(*array);
    if (!target_hash) {
        if ((*array)->type == IS_STRING && (*array)->value.str.val==undefined_variable_string) {
            RETURN_LONG(0);
        } else {
            RETURN_LONG(1);
        }
    }
    RETURN_LONG(zend_hash_num_elements(target_hash));
} is this the "right" way of doing it? i believe that 'cause of the double refrencing in zvals (old mac-programmers would call it a "handle") this should work in all cases - and its faster than before.
Yes, the code is correct. I practically forgot we introduced getParametersEx()... getParametersEx() is very suitable for that sort of function, that expects a certain type of argument, and does no implicit conversions if the supplied argument has a different type. If a certain function implementation does convert its arguments if they're not of a certain type, then you need to call SEPARATE_ZVAL() on the pointer before you may apply conversion routines on it. I wanted to write up some convert_to_*_ex() macros that do that automatically, but forgot about it. I'll look into it sometime soon.
PS: this count implementation is always "fast" 'cause it *NEVER* copies the parameters (getParameters would copy!).
That's absolutely true - that's why we added these new API functions to Zend. Since in many cases (probably most cases) arguments are of the type you expect them to be (i.e., there's no need for a conversion anyway) - using the new API may bring very considerable speedups (especially in functions that handle strings and arrays). Using this API is more dangerous, but when used carefully - it's worth it. Zeev -- Zeev Suraski <zeev@zend.com> http://www.zend.com/ For a PGP public key, finger bourbon@netvision.net.il

« previous php.version4 (#4439) next »