C API vs PHP API, e.g. gtk_tree_selection_get_selection
| From: | Markus Fischer | Date: | Mon, 23 May 2005 21:51:34 +0000 |
| Subject: | C API vs PHP API, e.g. gtk_tree_selection_get_selection | ||
| Groups: | php.gtk.dev | ||
| Request: | Send a blank email to php-gtk-dev+get-1322@lists.php.net to get a copy of this message | ||
Hi,
I'm not really happy with the way the API calls change from C to PHP in some places, for example in gtk_tree_selection_get_selection.
What is pretty clean in C looks quirky in PHP. I'm no real solution, just want to start discussions on what others think.
In C, the function would work like:
boolean_result = gtk_tree_selection_get_selected(tree, model, iter);
if boolean_result is true, model and iter will be initialized
if boolean_result if false, model is initialized, the iter isn't
now in PHP we will always get a return value, an array, and have to look into the array to decide if all has gone well or not:
always_array = $tree->get_selection()->get_selected();
and then we have to check whether always_array[1] is NULL or not, always_array[0] is always the model.
The model is optional in the C function, it's only provided for convinienve. I can't think of a case where you cannot access the model but only have the selection (at least if you develop carefully).
What do you think about the proposel to return the iter or false?
if (iter = $tree->get_selection()->get_selected()) {
// do something clever
}
vs.
array = $tree->get_selection()->get_selected()) {
if (!is_null(array[1])) {
// do something clever
}
The model would be available with $tree->get_model() if there would be no existing reference already.
cheers,
- Markus