PHP Fatal error: Call to a member function get() on a non-object

I have been seeing this error when installing D8.0 for more than a year now, but have ignored it because it doesn't seem to have any consequences.

Mon Nov 03 20:02:21.491327 2014] [:error] [pid 4671] [client ::1:50210] PHP Fatal error: Call to a member function get() on a non-object in /Users/rocks/Sites/drupal8/core/lib/Drupal.php on line 566

But now that D8.0 is beta it should be looked at before D8.0 release. The error message appears in my web server's(apache) error log before the first install page is displayed. It has happened across different versions of my OS(OS X), PHP, and apache. I initially reported this in #2223575: PHP Fatal error: Call to a member function get() on a non-object, but that issue seems to have become a catchall for problems with similar symptoms.

The error is only displayed in the web servers error log and not in Drupal's logs. I have tried to get more info by adding some var_dump()'s in _drupal_exception_handler(), but this error doesn't seem to go thru that code. I'd welcome any debugging tips.
To reproduce:
Start install for D8.0
Look at your web server's error log when the 1st install page is displayed.

Comments

dcrocks’s picture

I turned on xdebug and got a stack trace:

[Tue Nov 18 13:41:33.641586 2014] [:error] [pid 77484] [client ::1:58466] PHP Fatal error:  Call to a member function get() on a non-object in /Users/shifu/Sites/drupal8/core/lib/Drupal.php on line 575
[Tue Nov 18 13:41:33.641653 2014] [:error] [pid 77484] [client ::1:58466] PHP Stack trace:
[Tue Nov 18 13:41:33.641663 2014] [:error] [pid 77484] [client ::1:58466] PHP   1. _drupal_exception_handler() /Users/shifu/Sites/drupal8/core/includes/bootstrap.inc:0
[Tue Nov 18 13:41:33.641672 2014] [:error] [pid 77484] [client ::1:58466] PHP   2. _drupal_log_error() /Users/shifu/Sites/drupal8/core/includes/bootstrap.inc:885
[Tue Nov 18 13:41:33.641681 2014] [:error] [pid 77484] [client ::1:58466] PHP   3. Drupal::theme() /Users/shifu/Sites/drupal8/core/includes/errors.inc:128

Now to see what I can figure out.

13rac1’s picture

I've got the same issue with Mint 17 and PHP 5.5:

$ drush cr -d -v
Starting Drush preflight. [0 sec, 1.89 MB]                               [preflight]
Cache HIT cid: 7.0-dev-commandfiles-0-762315c32b9c4c2967e28ece366ba160       [debug]
[0.01 sec, 1.95 MB]
Bootstrap to phase 0. [0.05 sec, 5.67 MB]                                [bootstrap]
Bootstrap to phase 2. [0.05 sec, 5.68 MB]                                [bootstrap]
Drush bootstrap phase : _drush_bootstrap_drupal_root() [0.05 sec, 5.68   [bootstrap]
MB]
Initialized Drupal 8.0.0-dev root directory at /var/www/drupal8 [0.06       [notice]
sec, 6.07 MB]
Cache HIT cid: 7.0-dev-commandfiles-1-7fff19bbc12ceeb3a5f27a79b9dc405c       [debug]
[0.06 sec, 4.16 MB]
Drush bootstrap phase : _drush_bootstrap_drupal_site() [0.07 sec, 4.94   [bootstrap]
MB]
Initialized Drupal site default at sites/default [0.07 sec, 4.94 MB]        [notice]
Cache HIT cid: 7.0-dev-install_profile-66ecfeb9791a023150773849f1550c5d      [debug]
[0.07 sec, 4.95 MB]
Cache HIT cid: 7.0-dev-commandfiles-2-479111bf70279c120e2c405fd2f78a76       [debug]
[0.07 sec, 4.95 MB]
Found command: cache-rebuild (commandfile=cache) [0.07 sec, 4.95 MB]     [bootstrap]
Calling hook drush_cache_rebuild [0.11 sec, 7.02 MB]                         [debug]
PHP Fatal error:  Call to a member function get() on a non-object in /var/www/drupal8/core/lib/Drupal.php on line 161
Drush command terminated abnormally due to an unrecoverable error.       [error]
Error: Call to a member function get() on a non-object in
/var/www/drupal8/core/lib/Drupal.php, line 161 [0.11 sec, 7.34 MB]
13rac1’s picture

Status: Active » Closed (duplicate)
daffie’s picture

Status: Closed (duplicate) » Active

@eosrei: I do not think that that is a duplicate. I think that it has to do with drush and #2328111: Replace most instances of the DRUPAL_ROOT constant with the app.root container parameter.

I can confirm that with drush I get the same error as you do.

But if you do a "Clear all caches" on the page "admin/config/development/performance". I get no error.

Maybe the problem is with drush.

13rac1’s picture

@daffie This is the same error message. I also get this error in the logs during installation. #2223575: PHP Fatal error: Call to a member function get() on a non-object covers both instances (install and drush) already. See comment #16: https://www.drupal.org/node/2223575#comment-8625917

If we are sure the issue is with drush, then this should be closed and re-opened in the drush issue queue on github. At this point, I don't believe it to be the case.

daffie’s picture

I just did a clean install of the head-branch. Deleted the files directory. Droped all database tables. And copied settings.php and services.yml. It is a clean install. Before today I never had this problem. And also the error: PHP Fatal error: "Call to a member function get() on a non-object in /var/www/drupal8/core/lib/Drupal.php on line 161".

@eosrei: If you go to the page "admin/config/development/performance" and click on "Clear all caches" what do you get?

dcrocks’s picture

I want to keep this issue to the one error case. I created it because #2223575: PHP Fatal error: Call to a member function get() on a non-object has been clouded with multiple error scenarios with the same symptom. This error is repeatable across different environments and has been around for a long time. It also consistently fails on the same call in drupal.php:

  public static function theme() {
    return static::$container->get('theme.manager');
  }

If #2223575: PHP Fatal error: Call to a member function get() on a non-object is changed to focus on this one error, then I will close this one as a duplicate. Until then I am only interested in this single error scenario.

13rac1’s picture

@dcrocks Yes, Ok, that other issue is a mess of separate issues.

@daffie When I click "Clear all caches" Drupal does nothing. It acts like I refreshed the page. D7 installs work fine.

daffie’s picture

I have updated drush and for me the problem is gone.

anavarre’s picture

anavarre’s picture

Status: Active » Postponed (maintainer needs more info)

Changing status for now.

dcrocks’s picture

Status: Postponed (maintainer needs more info) » Active

My problem has nothing to do with drush. I can't seem to keep this conversation separate. However, the patch in #2363341: Throw exception in Drupal::service() and friends, if container not initialized yet. seems to fix my problem as well. If that goes final I'll close this as a duplicate.

anavarre’s picture

Apologies, I overlooked the issue summary.

jhedstrom’s picture

This specific error:

PHP Fatal error: Call to a member function get() on a non-object in /var/www/drupal8/core/lib/Drupal.php on line 161

was due to a bug in very early error handling, which has been fixed in #2317913: Early error handling can result in fatal error (Call to a member function get() on a non-object).

dcrocks’s picture

dcrocks’s picture

Status: Active » Closed (won't fix)

#2363341: Throw exception in Drupal::service() and friends, if container not initialized yet. has been committed and swallows this error, so I am going to close this.

tim.plunkett’s picture

Status: Closed (won't fix) » Closed (cannot reproduce)

I have no idea what error you think is happening during early install. Now that everything is centralized, you can even replace the thrown exception with die; and it will still install properly.

dcrocks’s picture

The error is as described in the summary. A PHP fatal occurs early in install as shown in the Apache error log. It is not my error, it is drupal's. It has been there a long time over multiple OS's and machines and has no apparent affect. But it is there. Since it has no apparent impact it wouldn't be seen unless you look at the Apache error log. Now it won't be seen at all because the exception is caught, but not recorded. I see no point now of pursuing it but as far as I am concerned, it hasn't been fixed and it is still occurring.