[Xapian-discuss] PHP Fatal error while indexing Wikipedia

Olly Betts olly at survex.com
Wed Jan 2 00:22:21 GMT 2008


On Tue, Jan 01, 2008 at 11:50:35PM +0000, Robert Young wrote:
> > Which xapian-bindings version is this?  Line 1482 doesn't seem to match
> > up with my tree.
> 1.0.4
> The function is
>   function index_text($text,$weight=1,$prefix=null) {
>     switch (func_num_args()) {
>     case 1: case 2:
> TermGenerator_index_text($this->_cPtr,$text,$weight); break; // <--
> line 1482
>     default: TermGenerator_index_text($this->_cPtr,$text,$weight,$prefix);
>     }
>   }
> 
> > It sounds like either you're passing in parameters with the wrong type,
> > or it's a bug in the wrappers SWIG is generating, but it's hard to know
> > which without seeing your indexer code.  The generated code looks OK to
> > me at least.
> >
> > My best guess is that maybe you are passing a string for the weight
> > parameter in some case - as the documentation says:
>
> As you can see from the code above, it doesn't look like it can be
> getting anything other than 1 or 2 for the weight.

I think you must be misreading the code - the switch is on
"func_num_args()", which in PHP returns the number of parameters which
were passed to the current function/method.  So $weight is either 1 or
whatever was passed to the index_text method.

> >     One thing to be aware of though is that SWIG implements dispatch
> >     functions for overloaded methods based on the types of the
> >     parameters, so you can't always pass in a string containing a number
> >     (e.g. "42") where a number is expected as you usually can in PHP.
> >     You need to explicitly convert to the type required - e.g. use (int)
> >     to convert to an integer, (string) to string, (double) to a floating
> >     point number.
> Ahh, that may be something. If the field value is empty it may be null
> rather than an empty string. I guess I shouldn't be indexing it either
> way really. I won't get another chance to run this until tomorrow but
> I'll let you know how it goes. Thanks for the pointer.

That sounds plausible.

It would be nice to give a better error for such cases, but it's not
easily to do because the handling code is generated by SWIG from the
parameter lists of the overloaded forms of the function or method.

Cheers,
    Olly



More information about the Xapian-discuss mailing list