Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hello,
I am getting the following error on one site when using drush commands..
Parse error: syntax error, unexpected T_FUNCTION in /data/www/../../sites/all/modules/contrib/webform/webform.module on line 4401
I have tried everything I can imagine (eg disable/enable module, delete module and data then re-install, try different module versions, run db updates etc etc.) with no luck.
I am hoping somebody here might understand what that error means and give some advice on how to fix it. Many thanks
Comments
Comment #1
DanChadwick CreditAttribution: DanChadwick commentedI'm venture that your download has been corrupted. I assure you that 4.7 does not have any parse errors. I would replace it with a freshly-downloaded copy.
Comment #2
Anonymous (not verified) CreditAttribution: Anonymous commentedI encountered the same error today while uploading a site. The error seems to happen with web form 7.x-4.7 and PHP 5.2. Switching to PHP 5.5 solved the issue for me (version 5.3 should work as well as that's the version mentioned in the webform.info file).
It might be useful to mention PHP 5.3 under "Requirements" in README.txt.
Comment #3
DanChadwick CreditAttribution: DanChadwick commentedThat's a good idea. I'm not going to duplicate the requirements from the project page in the readme, but rather reference the project page. That way it will always be updated.
Committed to 7.x-4.x and 8.x.
Comment #4
pyxio CreditAttribution: pyxio commentedHi I can assure you it is not a php error. Webform runs fine on other sites on the same server. So I simply do not understand what is causing this on one particular site. I will keep you posted of my findings. cheers kevin
Comment #5
DanChadwick CreditAttribution: DanChadwick commented@drupalstrap -- That line of code is an anonymous function. There are only 2 reasons I know of why PHP choke on an anonymous function.
1) Use of PHP < 5.3, where anonymous functions aren't supported.
2) Use of an opcode cache that doesn't support anonymous function. APC works. Searching the issue queue will reveal another that doesn't, whose name escapes me at the moment.
I'd venture that your other functioning sites either a) aren't displaying components b) are using an older version of webform, c) are using a newer version of PHP or d) aren't using the same op code cache.
Comment #8
pyxio CreditAttribution: pyxio commented@DanChadwick thanks for the suggestions. i will report back once i solve it. cheers kevin
Comment #10
arlingtonvoicellc CreditAttribution: arlingtonvoicellc commentedI have hit the same issue. Can confirm I'm using PHP 5.5. Only Webform module is breaking the website. Uninstalled the module and then reinstalled most recent version. Same error.
Parse error: syntax error, unexpected T_FUNCTION in ../sites/all/modules/webform/webform.module on line 4606
Comment #11
arlingtonvoicellc CreditAttribution: arlingtonvoicellc commentedComment #12
pyxio CreditAttribution: pyxio commentedyes. it is a php compatibility issue. i ended up using an earlier version of webform. it works but i have notices that i should upgrade the module due to security issue of the older one. but i can't update it because then the site breaks. so keeping the older one for now. cheers
Comment #13
arlingtonvoicellc CreditAttribution: arlingtonvoicellc commentedThanks Drupalstrap. Going to try an older version. I should note that the most recent version was working just fine on my WAMP. It was only when I migrated to a live server that it broke. My WAMP is using PHP 5.3.1.
Comment #14
DanChadwick CreditAttribution: DanChadwick commentedIt's your installation. Disable or update eAccelerator. See http://php.net/manual/en/functions.anonymous.php#113422
The syntax in Webform is correct for PHP 5.3 and higher.
Comment #15
arlingtonvoicellc CreditAttribution: arlingtonvoicellc commentedCall me crazy, but it seems backwards to push out a module update that requires you to turn off default settings on a server. Shouldn't the module adapt to the server, not the other way around?
Comment #16
DanChadwick CreditAttribution: DanChadwick commentedIt's a bug in eAccelerator, which has been (apparently) been fixed. Webform requires PHP 5.3. The affected version of eAccelerator doesn't support all of PHP 5.3 -- specifically anonymous functions.
eAccelerator is not a "default setting" of a server. It is add-on software (presumably added by a host company, and not kept up-to-date).
If you installed an add-on to Microsoft Word and it made Word crash every time you typed "Drupal", would stop writing about Drupal or would you remove or update the add-on?
Comment #17
arlingtonvoicellc CreditAttribution: arlingtonvoicellc commentedAdding an update here for anyone who has hit the same problem.
Because my client's website is on shared hosting, I had to disable the eaccelerator module through .htaccess.
Create an .htaccess file and add the following code:
Then upload this to the WEBROOT folder (aka public_html) of your server.
All of the articles I found online did not include the "IfModule" part of the above code. Without that part, it kept crashing the server with a 500 error. Hope this helps someone in the future.
Comment #18
rwilson0429 CreditAttribution: rwilson0429 commentedThe project page says that the 7.x-4.x requires php >=5.3. Since drush runs from the command line. I would check the php version of your CLI. At the command line where you normally run drush commands, type php -v. If the version is <5.3, that is probably the cause of the issue.
The php version that your website is running on is not necessarily the same version that your SSH or your CLI is running.
A workaround is to disable webforms when you need to perform drush operations that aren't webform specific. You can always re-enable after your drush operations are completed.
Comment #19
karolus CreditAttribution: karolus as a volunteer commentedThere may be another solution, depending on your Web host's setup. For my issue here, the server was running PHP 5.2, hence the error. No GUI method to fix, but adding this to the .htaccess file at the Web root (public_html) fixed it right up:
Hope this can help for some.
Comment #20
korn3lius CreditAttribution: korn3lius commentedI also encounter the same problem here. Fortunately, It solved. The problem in my case is differrent php version used by drupal site and drush. After I corrected my drush php version in bash_profile with the same with drupal site php. Drush is working properly.
Comment #21
kerrycurtain CreditAttribution: kerrycurtain commented@arlingtonvoicellc
Thanks very much for this piece on code, we have been down for over 3 days now and your sweet piece of code has returned us back to a visible domain.
Comment #22
Funksmaname CreditAttribution: Funksmaname commented#19 worked for me, thanks