[Xapian-devel] PHP Latest

Olly Betts olly at survex.com
Thu Apr 20 15:20:21 BST 2006


On Thu, Apr 20, 2006 at 03:48:06PM +0200, Daniel M?nard wrote:
> It seems, that while these variables are created by PHP, nothing 
> prevents one to use their name as the name of a function parameter. It 
> can't be considered as "good practice", it is not documented as 
> explicitely allowed, and of course it won't be possible from inside the 
> function to use the global predefined php var, but it seems to work (I 
> tested with php versions 4.3.10, 5.0.4 and 5.1.2 under windows and debian).
> Even using "$this" as a parameter name doesn't seem to clash anything !

Provided we don't use $this in the generated code...

So the only thing we need to perhaps check for is a prototype like:

class A {
    int b(int c, float c);
};

Which is valid as a declaration (although not for the actual definition)
and SWIG was changed to accept it because compilers do (due to an
example of this in xapian.i at one point!)

I think the change made SWIG rename the parameters in this case, but I
should check that this corner case works I guess.

> In my opinion, the only methods which still use call_user_func_array 
> (auto_open, quartz_open, muscat36_open_da, muscat36_open_db, mset.fetch, 
> enquire.getmset, delete_document, parse_query) are not aimed to be 
> called repeatedly, and the php overhead will probably be negligeactable 
> compared to the time taken by the function.

I should fix the patch to handle %rename-d methods/functions though,
since it should become a part of SWIG and in other wrapped libraries it
might matter more.

> Perhaps there is still some room for improvment in the constructors. 
> Many are still using call_user_func_array and I'm not sure that I 
> understand why.

I think it's because most classes have a default constructor and a copy
constructor so my patch sees:

Database::Database();
Database::Database(const Database & o);
Database::Database(const string & path);

So if we're happy for "new Database($foo)" to mean "new Database()" when
$foo is Null, it could be fixed, but I'm not totally sure that's a good
idea.

Alternatively, we can probably just ignore the default constructor in
cases where it only creates a useless dummy object - I think in PHP it
would be more natural to say "$db = Null;" rather than "$db = new
Database();" (hmm, actually this is a bad example, since it's not a
useless dummy object as you can then call "$db->add_database(...)" but
for many of the classes it's true).

> If I understood correctly, we wish to compare calling the flat functions 
> in the following versions :
> - 0.9.4 release version
> - 0.9.5 release version
> - 0.9.5 release version + xapian_wrap7.cc
> (0.9.4+patch won't compile because of the new method introduced)

Yes (you could try 0.9.4+patch and just nuke the wrapping bits for the
new method by hand actually, but that's probably not vital for working
out where the extra time went).

Cheers,
    Olly



More information about the Xapian-devel mailing list