Notice: Use of undefined constant DEBUG_BACKTRACE_IGNORE_ARGS - assumed 'DEBUG_BACKTRACE_IGNORE_ARGS' in Drupal\xautoload\Libraries\LibrariesFinderPlugin->findFile() (line 53 of /xautoload/src/Libraries/LibrariesFinderPlugin.php).

This issue is related to PHP 5.3.3

Was fixed here for render_cache:
#2177227: Warning: debug_backtrace() expects at most 1 parameter with php < 5.4

CommentFileSizeAuthor
#5 use_of_undefined-2365781-2.patch1.44 KBjoelpittet
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

donquixote’s picture

Would this work?

  function findFile($api, $logical_base_path, $relative_path) {
    // Prevent recursion if this is called from libraries_info().
    // @todo Find a better way to do this?
    $backtrace = defined('DEBUG_BACKTRACE_IGNORE_ARGS')
      ? debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS)
      : debug_backtrace(FALSE);
    foreach ($backtrace as $call) {
      if ('libraries_info' === $call['function']) {
        return FALSE;
      }
    }

Btw, I would prefer if this libraries stuff lived in an optional submodule. Now I have to support this in the main module for BC.

  • donquixote committed f497832 on 7.x-5.x
    Issue #2365781: DEBUG_BACKTRACE_IGNORE_ARGS is not available in PHP...
donquixote’s picture

Fixed in 7.x-5.x.

donquixote’s picture

Status: Active » Fixed
joelpittet’s picture

Status: Fixed » Needs review
FileSize
1.44 KB

Huh, I'm only using

function MODULE_xautoload($api) {
  $api->absolute()->composerDir('sites/all/vendor/composer');
}

Which I love btw!

I'm guessing your saying that libraries stuff loads anyways?

I'm sorry I still have a 5.3 server:( Here's a patch fixing both instances of that constant, I tested it out and it fixes things, thanks.

joelpittet’s picture

Oh you're too fast, I cross-posted. Want to cherry pick the other one out?

donquixote’s picture

I'm guessing your saying that libraries stuff loads anyways?

This is a more complicated story.
See #2297525: Libraries integration: Require libraries_load()..

Libraries API by itself is designed in a way that you need to call libraries_load() before anything from the library becomes available.
E.g. files being included.

xautoload libraries support, however, is designed so that the classes / namespaces are available on every request, without any libraries_load(). This might have been a bad decision, but now I support this for BC. Also it seems that most people really want this.

To make the libraries autoload stuff available, we need to get the closure from hook_libraries_info(). However we don't want to call module_invoke_all('libraries') on every request. And caching is difficult because closures cannot be serialized.

So the solution is:
- xautoload_libraries_info_alter() cleans out the closures from hook_libraries_info() data, and replaces them with SerializableClosureWrapper.
- On a request where the APC / APCu / whatever classmap cache is hot, we don't do any of this.
- If the classmap cache has a miss (which also happens if a class is forwarded to another autoloader), we retrieve the xautoload stuff from hook_libraries_info(), and execute the closures. This info is cached, using SerializableClosureWrapper.

Wicked, isn't it?
This works surprisingly well, but it makes the module look intimidating. Would really be better if this was in a submodule.

donquixote’s picture

Want to cherry pick the other one out?

I already pushed to drupal.org.

class DrupalSystem implements DrupalSystemInterface {

  function __construct() {
    if (!function_exists('drupal_get_filename')) {
      debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS);
      echo "\n\n";
      throw new \Exception("This class works only within a working Drupal environment.");
    }
  }

I think this code is never executed if the module is used correctly.
And for the case that it is, I wonder if the debug_print_backtrace() is really a good idea. It looks to me like a leftover from debugging.
The exception should be good enough.

joelpittet’s picture

Status: Needs review » Fixed

@donquixote I like your story:) And agree a submodule be preferable to keep it light on it's feet though BC breaking could be tricky. Something to add to a 7.x-6.x roadmap perhaps?

Just thought I'd be thorough as that same constant was there, but I've not run into that DrupalSystem error so not too concerned.

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

donquixote’s picture

Too bad I missed to add you in the commit message.
You get some "fake credit" in exchange :)
http://cgit.drupalcode.org/xautoload/commit/?h=7.x-5.x&id=80f05502177572...

donquixote’s picture

So the solution is:
- xautoload_libraries_info_alter() cleans out the closures from hook_libraries_info() data, and replaces them with SerializableClosureWrapper.
- On a request where the APC / APCu / whatever classmap cache is hot, we don't do any of this.
- If the classmap cache has a miss (which also happens if a class is forwarded to another autoloader), we retrieve the xautoload stuff from hook_libraries_info(), and execute the closures. This info is cached, using SerializableClosureWrapper.

Actually it is even more fancy :)

  1. xautoload_libraries_info_alter() cleans out the closures from hook_libraries_info() data, and replaces them with SerializableClosureWrapper.
  2. On a request where the APC / APCu / whatever classmap cache is hot, we don't do anything.
  3. If the classmap cache has a miss (which also happens if a class is forwarded to another autoloader), we register a number of lazy plugins. One of them is for libraries. "Chain of responsibility" !
  4. If the lazy plugin for libraries is asked to load a class for the first time (which only happens if the other plugins fail), we retrieve the xautoload stuff from hook_libraries_info(), and execute the closures. This info is cached, using SerializableClosureWrapper.
joelpittet’s picture

I'll take it:) Thanks and very cool strategy