customized usort && pass by reference...

From: Date: Tue, 06 Mar 2001 16:18:09 +0000
Subject: customized usort && pass by reference...
Groups: php.dev 
Request: Send a blank email to php-dev+get-48063@lists.php.net to get a copy of this message
Hi! In my (C-)module I'm building a customized usort function, that accepts an object as the first argument, and a user-defined function as the second. The object contains an array that I want to sort using the user-defined compare function. If I simulate this in PHP-script, the behaviour should be like function special_object_sort(&$so, $compare_function) { // check object validity here // and sort it if ok usort($so->data, $compare_function); } // (note the reference in front of the first argument) // ... special_object_sort($my_object, "my_compare_function"); What I actually get is that the $so parameter is not changed. All the C- functions get called, the compare-function gets called, so I suspect that it has something to do with pass by reference/value. Now, since call-time pass-by-reference is deprecated, I need some way to create the function mentioned above in C-code. (otherwise I could have used special_object_sort( & $my_object, "my_compare_function"); ) Here follows a C-snippet (with lots of stuff left out) that indicates how things work now zend_get_parameters_array_ex(number_of_arguments, arguments); if ((*arguments[0])->type != IS_OBJECT) RETURN_LONG(0); if (zend_hash_find((*arguments[0])->value.obj.properties, "data", 5, (void **) &zval_data)==FAILURE || (*zval_data)->type != IS_ARRAY) { RETURN_LONG(0); } passthru_arguments[0] = zval_data; passthru_arguments[1] = arguments[1]; call_php_function("usort", &returned_zval, number_of_passthru_arguments, passthru_arguments); RETURN_LONG(1); This acts as though I had implemented the PHP-script function mentioned above, but without the reference in front of the first argument. Can anyone help me to get the code to work?

« previous php.dev (#48063) next »