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?
--
PHP Development Mailing List <http://www.php.net/>
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]