Skip to content

Conversation

@hektech
Copy link

@hektech hektech commented Jun 7, 2017

(This pull request was originally posted for LibraryHost/archon, but it was suggested to move the conversation over here instead.)

We are in the process of adopting Archon at Hekman Library, Calvin College. After getting it up an running on a PHP 5.6 test server, we then ran into some compatibility issues with PHP 7 on our production server.

The contents of this pullrequest got us to a working state. There may be more changes lurking in areas of the code we haven't exercised (similar to the small tag fix in the EAD export, included here), but we are now able to browse, search, and do DB imports successfully on our production server.

See the commit comments for much more detail on these changes, and why they are needed.

hektech added 3 commits May 18, 2017 16:39
Archon's object composition technique makes heavy use of a PHP
feature allowing method calls from an incompatible context. However,
this ability was deprecated in PHP 5.6 and removed from PHP 7.0 [1].

Ultimately, it seems like moving over to Traits may be a logical path
forward.  This patch instead attempts to allow current Archon to run
on PHP 7+ with the fewest changes possible.

Rather than simply attempt the method call in the wrong context, we
instead create a closure in the desired class, then insert our current
context into that closure using bindTo.

There may, of course, be a simpler way to do this.  In particular, it
seems messy to need to create an object only to get the closure.  I
do not claim to be an expert in PHP internals, but this functions, and
is decently boiled down.

This new technique should be supported for PHP >= 5.4.0, but this is
untested.  One questionable area would be the use of the getClosure
method call on a parenthesized "new" object statement.  I believe it is
supported syntax on at least 5.6, and would be very easy to work around
in any case.  That said, it may be better to retain the old technique
and branch within the code to suit the running version.

[1] http://php.net/manual/en/migration56.deprecated.php#migration56.deprecated.incompatible-context

Signed-off-by: Dan Wells <dbw2@calvin.edu>
$OutputQueries is not static, so we need $this here.  Older versions
of PHP (<7.0) were more lax about this, particular the way we were
mixing contexts.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
PHP no longer supports "<?" as an opening tag; make it read "<?php"
instead.

Signed-off-by: Dan Wells <dbw2@calvin.edu>
@hektech
Copy link
Author

hektech commented Jun 7, 2017

Original pull request, for reference: LibraryHost#9

@tpwalsh
Copy link

tpwalsh commented Oct 29, 2018

I copied this code out but was having some difficulty running it(it produces a blank page, with the following log output). The issue seems to stem from the bindTo($this) call trying to change scopes.

Cannot bind method Core_QueryLog::logQuery() to object of class QueryLog in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 283

Cannot bind method Core_Archon::initialize() to object of class Archon in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 283

I'm not entirely sure that I'm not missing something in my configuration though. I did have to change the Server type to MySQLi: $_ARCHON->db->ServerType = 'MySQLi'; since MySQL is now dead.

Is this something you've run into?

Full log output:

Mon Oct 29 15:14:24.975317 2018] [php7:warn] [pid 11601] [client 10.4.8.189:54871] PHP Warning:  Creating default object from empty value in /var/www/html/archon_sc/config.inc.php on line 59
[Mon Oct 29 15:14:24.975344 2018] [php7:warn] [pid 11601] [client 10.4.8.189:54871] PHP Warning:  Creating default object from empty value in /var/www/html/archon_sc/config.inc.php on line 153
[Mon Oct 29 15:14:24.975660 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Undefined index: p in /var/www/html/archon_sc/start.inc.php on line 25
[Mon Oct 29 15:14:24.975714 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Undefined property: stdClass::$Constructed in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 164
[Mon Oct 29 15:14:24.981418 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Undefined property: stdClass::$Parameters in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 262
[Mon Oct 29 15:14:24.981447 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Trying to get property of non-object in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 262
[Mon Oct 29 15:14:24.981513 2018] [php7:warn] [pid 11601] [client 10.4.8.189:54871] PHP Warning:  Cannot bind method Core_QueryLog::logQuery() to object of class QueryLog in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 281
[Mon Oct 29 15:14:24.981535 2018] [php7:warn] [pid 11601] [client 10.4.8.189:54871] PHP Warning:  call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 283
[Mon Oct 29 15:14:24.981552 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Undefined property: stdClass::$Parameters in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 285
[Mon Oct 29 15:14:24.981565 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Trying to get property of non-object in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 285
[Mon Oct 29 15:14:24.981929 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Undefined property: stdClass::$Parameters in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 262
[Mon Oct 29 15:14:24.981956 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Trying to get property of non-object in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 262
[Mon Oct 29 15:14:24.981980 2018] [php7:warn] [pid 11601] [client 10.4.8.189:54871] PHP Warning:  Cannot bind method Core_QueryLog::logQuery() to object of class QueryLog in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 281
[Mon Oct 29 15:14:24.981997 2018] [php7:warn] [pid 11601] [client 10.4.8.189:54871] PHP Warning:  call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 283
[Mon Oct 29 15:14:24.982013 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Undefined property: stdClass::$Parameters in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 285
[Mon Oct 29 15:14:24.982025 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Trying to get property of non-object in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 285
[Mon Oct 29 15:14:24.982398 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Undefined index: p in /var/www/html/archon_sc/start.inc.php on line 107
[Mon Oct 29 15:14:24.982420 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Undefined index: p in /var/www/html/archon_sc/start.inc.php on line 107
[Mon Oct 29 15:14:24.982442 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Undefined property: stdClass::$Parameters in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 262
[Mon Oct 29 15:14:24.982456 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Trying to get property of non-object in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 262
[Mon Oct 29 15:14:24.982576 2018] [php7:warn] [pid 11601] [client 10.4.8.189:54871] PHP Warning:  Cannot bind method Core_Archon::initialize() to object of class Archon in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 281
[Mon Oct 29 15:14:24.982599 2018] [php7:warn] [pid 11601] [client 10.4.8.189:54871] PHP Warning:  call_user_func_array() expects parameter 1 to be a valid callback, no array or string given in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 283
[Mon Oct 29 15:14:24.982616 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Undefined property: stdClass::$Parameters in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 285
[Mon Oct 29 15:14:24.982629 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Trying to get property of non-object in /var/www/html/archon_sc/packages/core/lib/archonobject.inc.php on line 285
[Mon Oct 29 15:14:24.982648 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Use of undefined constant CONFIG_CORE_PUBLIC_ENABLED - assumed 'CONFIG_CORE_PUBLIC_ENABLED' in /var/www/html/archon_sc/start.inc.php on line 120
[Mon Oct 29 15:14:24.982668 2018] [php7:notice] [pid 11601] [client 10.4.8.189:54871] PHP Notice:  Undefined property: Archon::$Script in /var/www/html/archon_sc/index.php on line 11
[Mon Oct 29 15:14:24.982748 2018] [php7:warn] [pid 11601] [client 10.4.8.189:54871] PHP Warning:  require_once(/var/www/html/archon_sc): failed to open stream: Success in /var/www/html/archon_sc/index.php on line 11
[Mon Oct 29 15:14:24.982777 2018] [php7:error] [pid 11601] [client 10.4.8.189:54871] PHP Fatal error:  require_once(): Failed opening required '' (include_path='.:/usr/share/pear:/usr/share/php') in /var/www/html/archon_sc/index.php on line 11

@hektech hektech mentioned this pull request Nov 6, 2018
@hektech
Copy link
Author

hektech commented Nov 6, 2018

Thank you for testing tpwalsh! Unforunately, you are right the technique we were using successfully on 7.0 no longer works on 7.1+. I closing this pull request in favor of changes on #90 which have better compatibility.

@hektech hektech closed this Nov 6, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants