[Xapian-tickets] [Xapian] #817: Add PHP 8 support

Xapian nobody at xapian.org
Tue Jan 25 03:35:29 GMT 2022


#817: Add PHP 8 support
-----------------------------------+---------------------------
 Reporter:  Ryan Schmidt           |             Owner:  (none)
     Type:  enhancement            |            Status:  new
 Priority:  normal                 |         Milestone:
Component:  Xapian-bindings (PHP)  |           Version:  1.4.19
 Severity:  normal                 |        Resolution:
 Keywords:                         |        Blocked By:
 Blocking:                         |  Operating System:  All
-----------------------------------+---------------------------
Comment (by Olly Betts):

 > Is there a way to build bindings for php7 and php8 same time?

 There isn't a way to build working php8 bindings at all yet.  Once there
 is it's unlikely that there will be a 1.4.x release which support both
 PHP7 and PHP8.  That may not be ideal, but please understand it's not easy
 to support both in one xapian-bindings release.

 SWIG 4.1.0 brings a much needed major change in how SWIG generates PHP
 class wrappers - until now SWIG generated wrappers for a load of "flat"
 functions in C code and also generated a `.php` file containing class
 definitions with methods which forward to those flat functions.  There
 have been a lot of corner case bugs with this over the years, many of
 which never got fixed because they were too hard.  Now SWIG will generate
 the classes and their methods directly using PHP's C API.  This has fixed
 a whole slew of bugs and should be faster too.

 However, currently in Xapian's PHP bindings we post-process the
 `xapian.php` wrapper to add PHP type declarations (aka "type hints") and
 also to add code to keep references to set objects (so e.g.
 `XapianQueryParser::set_stemmer()` keeps a reference to the currently set
 stemmer).  We can't post-process `xapian.php` to do this now because the
 classes and methods aren't defined there any more.

 I don't have a solution for the ownership tracking yet, but maybe #714
 offers an answer.  Once we solve this I'd expect that solution would work
 for PHP7 too.

 But as for type declarations, SWIG 4.1.0 will automatically generate those
 for us but only for PHP 8.  PHP7 type declarations are much more limited
 (you can only have one type, optionally nullable, whereas PHP8 allows e.g
 `int|object`) and as a result the C API for this changed in PHP8.  For
 SWIG we concluded it didn't make sense to implement support for the
 limited old-style type declarations when PHP7 is 10 months from end of
 life).  So SWIG generates a single wrapper you can use with PHP7 or PHP8
 but it doesn't have type declarations for PHP7.  That's reasonable in
 general, but for Xapian it's means the PHP7 bindings would lose the type
 declarations we currently add, which would be a regression.

 So the easiest approach from the Xapian viewpoint is to have a hard switch
 from PHP7 to PHP8.  Anything else either requires that we have to use two
 different SWIG versions to generate a single release and two sets of the
 interface files, etc, or to add support for PHP7 type hints to SWIG.

 I can see that might be awkward for a Linux distro shipping packages, but
 at least binary packages aren't really feasible currently due the GPL vs
 PHP licence incompatibility (see #191).  Do you not distribute binary
 packages for the PHP bindings?  Or are you ignoring this licensing problem
 with doing so?  The next Xapian release series should address that by
 relicensing to MPL, but 1.4.x contains a lot of code we can't relicense.

 I'm already fighting a significant backlog of things I haven't got to yet,
 so I simply can't commit to doing extra work simply to support PHP7 and
 PHP8 in one release.  I've already put in a lot of work just to support
 PHP8 at all, and there's still more to go there.

 If you need to manage a transition, my suggestion would be to create a
 "xapian-bindings-php7" source package which is just the last xapian-
 bindings 1.4.x version before the switch to PHP8.
-- 
Ticket URL: <https://trac.xapian.org/ticket/817#comment:5>
Xapian <https://xapian.org/>
Xapian


More information about the Xapian-tickets mailing list