1

Class autoloading isn't working in custom module to extend webforms. Trying to call a function like this:

$utility = new webform_kk_utility();
$utility->getComponents('aaa')

getting this error:

[Mon Sep 21 20:29:28.287580 2015] [:error] [pid 15908] [client ******:39831] PHP Fatal error:  Class 'webform_kk_utility' not found in /var/www/html/sites/all/modules/webform_kk/webform_kk.module on line 12

Here's my code:

webform_kk.info:

name = Webform kk
description = custom webform code
core = 7.x
package = Webform
dependencies[] = webform
files[] = includes/utility.inc

webform_kk.module:

<?php

function webform_kk_form_alter(&$form, &$form_state, $form_id) {
    if ($form_id == 'webform_client_form_1') {
        $first = array_shift($form['#submit']);
        array_unshift($form['#submit'], $first, 'webform_kk_submit_1');
    }
}

function webform_kk_submit_1(&$form, &$form_state) {
    $utility = new webform_kk_utility();
    echo $utility->getComponents('aaa');
    die();
}

includes/utility.inc:

<?php

Class webform_kk_utility {
    function getComponents($components) {
        return $components;
    }
}

I tested the code without calling the external function, the code is running and the form submit dies where expected. I tried disabling, uninstalling the module and clearing the cache.

Thanks for the help.

1 Answer 1

1

"Class" -> "class".
It needs to be lowercase, or else Drupal does not discover it while scanning the file.

2
  • What, really?!! Jeez, that's a hell of a bug.
    – Clive
    Sep 22, 2015 at 7:55
  • Thanks, I never would have guessed that! I tried a dozen combinations of changing the actual class name and include file name, thinking the case might need to be different, or the module name should / shouldn't be included in the class.
    – kaisk23
    Sep 22, 2015 at 11:32

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.