[Xapian-discuss] PHP bindings

Daniel Ménard Daniel.Menard at Bdsp.tm.fr
Tue Oct 3 12:51:33 BST 2006


Francis Irving a écrit :

>On Mon, Oct 02, 2006 at 12:32:12PM +0100, Olly Betts wrote:
>  
>
>>Currently the PHP4 bindings use a SWIG option which flattens the
>>object interface into a series of functions, so you have to write:
>>
>>  $database = new_Database("mydb");
>>  echo Database_get_doccount($database) . " documents\n";
>>
>>instead of the more natural:
>>
>>  $database = new Database("mydb");
>>  echo $database->get_doccount() . " documents\n";
>>
>The related thing that I would like fixing is the way the Xapian
>function contaminate the global "namespace" (in as much as PHP4 or
>PHP5 have namespaces!). Other PHP libraries use a prefix on functions.
>Xapian could use xapian_ or maybe just xap_. 
>
>So, for example, I'm suggesting:
>    $database = new xapian_Database("mydb");
>Which obviously adds fewer extra prefixes when using the object
>oriented interface that you suggest, as you only need it for the
>object construction functions.
>  
>
It is the case, now : in the new PHP5 OO bindings all classes are 
prefixed with 'Xapian' (XapianDocument, XapianDatabase, XapianMset and 
so on) and general 'global' functions (xapian version, auto_open...) 
become static methods of an abstract class named 'Xapian'.

I think that Olly's example should read: $database=new 
XapianDatabase("mydb");

Looking at the latest wrapper source from 
http://www.oligarchy.co.uk/xapian/trunk/ , I don't see anything which 
could be considered as global namespace contamination, excepted a small 
$ext variable at the begining which could be eliminated.

BTW: I'm not sure at all that trying to dl() the extension in the 
wrapper if it is not loaded is a good thing... It is useful to pass the 
smoketest, but is it for anything else?

>>So if you use the Xapian bindings under PHP4 (not PHP5!), do you think
>>the pain of updating your code is worth the gain from the more OO-like
>>API?  If there was a simple script which did most of the work of
>>updating your scripts, would that change your opinion?
>>    
>>
I would forget about OO under PHP4, keeping the flat bindings as they 
are, and would target only PHP5.
(I don't have any PHP4 code to migrate...)
With all the work Olly did (and I know it was a lot of work!), the PHP5 
bindings are very 'friendly' to use and are very close to the native 
xapian API. If we target PHP5, they can even be improved in the future, 
perhaps adding some SPL interfaces (e.g. native iterators) or things 
like type hinting in arguments lists. If we must also support PHP4 OO, 
we won't be able to add these kinds of things.

>>Also, PHP5 seems to be significantly better than PHP4 in a number of
>>ways, and my impression is that PHP5 adoption has reached critical mass.
>>I think PHP4's days are numbered at this point.
>>    
>>
>
>We've not seen a good reason to even consider PHP5 yet. 
>
>Are there any performance benefits? For example, it still doesn't seem
>to cache compiled bytecode.
>  
>
There are some speed gains, but in my opinion the benefits are about the 
improvments in the language itself (far better OO support, E_STRICT, SPL 
interfaces, reflexion and so on).
Concerning the bytecode cache, you can easily add one (I believe PHP6 
will include one).

Best regards,

-- 

Daniel Ménard

Banque de Données Santé Publique
Avenue du Professeur Léon Bernard
35043 Rennes Cédex

Tél. (+33) 2.99.02.29.42
Fax (+33) 2.99.02.26.28
E-mail Daniel.Menard at Bdsp.tm.fr
http://www.bdsp.tm.fr




More information about the Xapian-discuss mailing list