Maybe I am doing something wrong but... I am trying to integrate XAutoload with the D7's form API.

I have this function:

"\Drupal\prevencionintegral\Forms\FormInscripcionCongreso::Validate"

I'm using that as the forms validation callback.

Now, when the Form API tries to call it back this fails:

      $function($form, $form_state);

But this works:

      call_user_func_array($function, array($form, &$form_state));

Does that mean that autoloading will not work when a function is called as in the first failing example?

($function is a string variable holding the full qualified function name as posted at the begining)

Thanks!

BTW @donquixote awesome work with this module, congratulations, this is smoothing a lot D7-D8 transition and making D7 way more maintainable.

Comments

david_garcia’s picture

Issue summary: View changes
donquixote’s picture

Category: Bug report » Support request
Priority: Critical » Normal
Status: Active » Fixed

Hi,
this is an issue with how PHP functions are called, not with this module or with autoloading.

http://3v4l.org/cITir


class C {

    function foo() {
        print __METHOD__ . "\n";
    }

    static function fooStatic() {
        print __METHOD__ . "\n";
    }
}

$function = array(new C(), 'foo');
$function();  // Output: "C::foo"

$function = array('C', 'fooStatic');
$function();  // Output: "C::fooStatic" in PHP 5.4.0+, but "Fatal error: Function name must be a string" in older versions.

$function = "C::fooStatic";
$function();  // Fatal error: Call to undefined function C::fooStatic()

Status: Fixed » Closed (fixed)

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