archonproject/archon

PHP 7.2 compatibility

Opened this issue · 8 comments

Now that PHP5.6 and prior is deprecated, has anyone done any work to upgrade the code to be PHP7 compatible? I've done just the barest testing and see that 3.21 doesn't work on PHP 7.1.22. As we have no plans to upgrade to archivespace or any other package right now I'll need to update the code, but would like to coordinate this work if anyone else is doing the same.

-Tim Walsh
Illinois State University.

Tim, I see you commented on the pull request thread related to PHP 7.X compatability, but I thought I'd drop a link to it here as well for others who might find the initial question: #90

We've just begun moving to a new server and discovered that Archon is not happy there. There may be more errors, but it looks like MDB2 is not compatible with PHP 7.2. Among other things, it depends on assigning new objects by reference using the syntax $whatever =& new Thingy();. That was deprecated under the 5.x line and has now been removed entirely.

I'm thinking of tearing out MDB2 altogether and replacing it with some other database abstraction layer -- perhaps just the native PDO functions. I'm not sure exactly how much work that would be, and I wouldn't really be able to test it properly, as I only have access to MySQL and SQLite databases (meaning I couldn't test MSSQL among others).

I haven't investigated far enough to determine if there are any other syntax changes necessary to get it up and running, but it wouldn't surprise me.

It's looking like switching from MDB2 to PDO is going to require some pretty extensive work. I forked a copy and began looking into it. I count 750-ish calls to MDB2 scattered across 86 files, all of which will need to be touched. Thankfully they both support prepared statements, so I think most of the actual queries can be reused as-is, but the syntax for preparing/executing them is different.

I also need to take a hard look at whether PDO can be made to return its output in a way that matches MDB2, so as to avoid needing to rewrite the code that processes results afterwards. They're both capable of fetching associative arrays, and I think that's mostly how Archon does it. So I'm hopeful that there won't be many changes required on that front.

EDIT: Hold the phone, it looks like MDB2 is getting updated. I see commits for PHP7 compatibility on MDB2's git repository within the last 24 hours. I'll be watching that with interest and probably wait to see if anything comes of it before seriously diving into an MDB2-PDO rewrite.

wickr commented

I've had very similar experiences as @wdmartin in evaluating PHP7 compatibility and looking at PDO. The earlier Pull Requests by @hektech were nice but I was wondering how MDB2 was being handled.

It doesn't look like there's been much more movement on the MDB2 GitHub for PHP7, at least not any type of release that I can find.

I've got our Archon running in Docker with PHP 5.3 ( https://github.com/osulp/archon ) and am trying to use that setup but with a different image for PHP 7, but without MDB2 I'm not getting very far.

Does anyone have any progress changing to PDO or any other ideas?

I've been working on this for the last couple of days, and I think it needs more work than just switching to PDO instead of MDB2. I've modified start.inc.php to connect to a MySQL or MariaDB instance -- that wasn't too hard -- but then $_ARCHON->initialize() dies.

It looks like there's a fairly complex system written in there to implement Mixins. If my research is correct, Mixins are used to share and reuse code across multiple classes, even when the two do not necessarily share a parent class or similar. You stick the code you want to reuse into a class by itself, and then it gets "mixed in" to the classes where you want to use it.

That's dandy, except PHP doesn't have Mixins. Or at least, it didn't have Mixins at the time Archon was initially written. As of PHP 5.4 there's a subsystem called Traits that does basically the same thing, though I suspect some of the details may vary.

Anyway, it looks like when you get to the $_ARCHON->initialize() call at the end of start.inc.php, the magic function __call() gets called instead, and it goes through some moderately complex contortions in order to implement Mixins using a blend of call_user_func_array(), and eval(). The latter makes me twitchy. Using eval allows for some very useful meta-programming, but because it involves executing constructed strings as PHP code, it also has some severe security implications in the event that a hostile actor ever figures out a way to inject strings of their own into the program.

Aside from that, the Mixins subsystem in Archon has some other problems when running under PHP 7. For one thing, it appears to depend on some information which no longer being loaded correctly. For example, this line:

if($_ARCHON->Mixins[get_class($this)]->Methods[$method]->Parameters[$MixinClass]->MixOrder == MIX_AFTER)

After substituting in the actual values of the variables in the above, it evaluates as:

if($_ARCHON->Mixins['Archon']->Methods['initialize']->Parameters['Core_Archon']->MixOrder == MIX_AFTER)

This is supposed to load a constant called MIX_AFTER or MIX_BEFORE which determines the method (and timing?) for mixing in the specified method, in this case initialize(). But ... The Parameters property is no longer present in PHP 7. It's just not there, so any reference to it causes the script to die with the following errors:

Notice: Undefined property: stdClass::$Parameters in /home/wdmartin/public_html/archon/packages/core/lib/archonobject.inc.php on line 21

Notice: Trying to get property 'MixOrder' of non-object in /home/wdmartin/public_html/archon/packages/core/lib/archonobject.inc.php on line 21

Parse error: syntax error, unexpected '->' (T_OBJECT_OPERATOR) in /home/wdmartin/public_html/archon/packages/core/lib/archonobject.inc.php(26) : eval()'d code on line 1

I don't know why the Parameters part of the data is not being loaded along with the rest of it. For that matter, I've spent two days fiddling with the Mixins subsystem and I'm still not entirely sure I understand exactly how it works. Which is going to make it hard to fix/replace.

Anyway, I'm working on it, but getting Archon running on PHP 7 is looking like a pretty long project at the moment.

Another contributor has updated a pending pull request to address the "Core_Archon"/Mixins issue you mention: #90

I haven't had a chance to experiment with it myself, but perhaps this patch could get farther down the road!