Re: C API vs PHP API, e.g. gtk_tree_selection_get_selection
| From: | Andrei Zmievski | Date: | Mon, 23 May 2005 23:11:32 +0000 |
| Subject: | Re: C API vs PHP API, e.g. gtk_tree_selection_get_selection | ||
| References: | 1 | Groups: | php.gtk.dev |
| Request: | Send a blank email to php-gtk-dev+get-1323@lists.php.net to get a copy of this message | ||
On May 23, 2005, at 2:51 PM, Markus Fischer wrote:
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).Some people don't develop carefully, I guess.
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.I modeled the PHP API mainly on PyGTK. If there is a better way to do something, I am open to changes, if there is a consensus about it. -Andrei