[Xapian-discuss] PHP bindings

Olly Betts olly@survex.com
Wed, 26 May 2004 14:26:58 +0100


On Wed, May 26, 2004 at 11:14:04AM +0100, Sam Liddicott wrote:
> I'm pretty sure all the xapian object methods are implemented as php object
> methods not global classless methods.
> 
> So Xapian::Auto::open should only work as a method of Xapian_Auto or maybe
> Auto.

Xapian::Auto is a namespace, not a class.  Xapian::Auto::open is a
function not a method (it's a factory function which returns a new
Xapian::Database or Xapian::WritableDatabase object - if you're not
familiar with the idea, think of it as an out-of-class constructor).

A reason for the factory functions is so that backends can be added
without changing the API of the database classes (although now I come
to think about it, the Auto pseudo-backend could be implemented as a
static method of the database class - but that still leaves the backend
specific factory functions, like Xapian::InMemory::open).  The eventual
aim is to allow backends to be implementable by the user (much as
weighting schemes can already be).

Methods of classes do get a prefix (though it's database_ not
xapian_database which may not be to some people's taste - names like
database_ and document_ are very generic and likely to be used by
other libraries).

C++ allows you to choose - you can "use namespace Xapian;" or "use
Xapian::Database;" if you wish.  You can even alias a shorter name
to Xapian.  Perl allows at least the first two.  The problem with
using a prefix as a pseudo-namespace is that there's no language
support for importing names from it.

Cheers,
    Olly