[Xapian-discuss] Another PHP 5 wrapper...

Daniel Ménard Daniel.Menard at Bdsp.tm.fr
Thu Apr 6 15:28:35 BST 2006


Olly Betts a écrit :

> A very important issue is that it needs to be easy to update the
> bindings. (...)
>
> Paul's __call trick is very handy for this (...)
>
> (...)I'd favour getting SWIG to generate the
> wrapper code rather than trying to maintain it by hand.  Kevin Ruland
> (the current SWIG PHP maintainer) is looking to move SWIG's PHP support
> in this direction anyway. 

I totally agree with the "easy maintenance" argument : if SWIG is able, 
in a near future, either to generate native OO extension for PHP, or to 
generate a PHP wrapper around flat bindings, this is a far better approch.

Do you know if/when adding this feature to SWIG is planned ?

> I must admit that camelCase as a PHP convention is news to me
> - from what I've seen PHP's core seems to actively eschew naming
> conventions.  But if PHP moving towards a convention that would be a
> step forward and it would be good to follow it.  Recent versions of
> SWIG can actually do the renaming automatically, though we have to
> specify a list of special cases for C# (because the C++ naming is a
> little irregular - e.g get_doccount -> GetDocCount).

It is just my opinion, and what I can see in some projets (Zend 
framework, EZ components, "a la rails" frameworks like CakePhp or 
Symfony, etc.), that using consistent naming conventions is gaining some 
popularity in the PHP world.
Perhaps that using in the OO php bindings exactly the same methods name 
as in the C# binding would be a good compromise (when I wrote the 
wrapper, I rather followed the java bindings).

>> - target : PHP >= 5.1
>
> I don't really have any idea which PHP versions are prevalent.  I'm
> guessing PHP4 is still fairly widely used and will continue to be for
> a while to come, so it would be good to keep the existing bindings for
> that (possibly with proxy classes reenabled to give an OO interface).

In my opinion, OO programming is really useable in PHP 5, not in PHP 4...
Having a compatible (php 4 *and* php 5) OO binding will require somme 
additional work (different constructors and destructors styles, for 
example), and I'm afraid we won't be able to use recent interfaces like 
iterators.
Personnally, I would keep PHP 5 as the target for OO binding. If I was 
to develop a PHP 4 project, I would use the actual (flat) swig bindings 
: they work very well and are consistent with usual php functions.

> But what's the issue with PHP 5.0 here?  I'm assuming there's something
> useful which was added in 5.1, but 5.0 still seems to be common (it's
> the version in the latest Ubuntu release for example) so it would be
> good to support it with OO wrappers, albeit possibly with some nice
> "PHP-ish" feature missing.

A lot of bugs introduced in php 5.0 were corrected in php 5.1 (iterators 
and spl classes are concerned by some of them), so 5.1 is my personal 
target, and I didn't think a lot before adding this requirement...
In my wrapper, this requirement is only caused by the use of the php 
"countable" interface.
It can be considered as a gadget : it allows to use the php count 
function on xapian objects (MSet, RSet...), but it is redundant with the 
size() method.
Other interfaces (Iterator, IteratorAggregate, ArrayAccess...) which can 
be usefull were all introduced in php 5.0.

> If dispatching a method call from a language to C++ incurs a large
> overhead it may be possible to address this by writing a "fat" wrapper
> class which buffers postings and passes them all over in one go (which
> would need some special code on the C++ side, but SWIG allows that).

hum... I think that we must be sure that there is such an overhead 
before adding binding specific code (and perhaps specific bugs !).

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