Problem/Motivation

After upgrading to php7, my server gives a 500 error caused by a php syntax error in the module file (filter settings callback function).

Error message:

"PHP Fatal error: 'break' not in the 'loop' or 'switch' context in htmLawed.module"

Relevant module code block:

function _htmLawed_settings($form, &$form_state, $filter, $format, $defaults, $filters) {
  if (!user_access('administer filters')) {
    break;
  }

This code appears to be in both 7.x and 8.x branches.

As per php spec, break must appear inside a loop or switch. For some reason php 5 didn't worry too much about this, but php7 doesn't like it. There is an undocumented behavior in php 5 where a break behaves like exit() in terminating a script when outside of a loop structure.

Server setup
nginx: 1.9.10
php: 7.0.3 (error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT)
OS: Windows 10

Proposed resolution

I've currently just replaced the break; with return FALSE; to get around the immediate issue. I'm not sure if that was the original intention of the module creator. There may need to be a filter permissions check earlier on in the call stack if that was the purpose of this code block...?

Comments

murraybiscuit created an issue. See original summary.

murraybiscuit’s picture

Issue summary: View changes
murraybiscuit’s picture

Issue summary: View changes
alpha2zee’s picture

Thank you for pointing this out. Your code replacement solution is OK, but I think the entire IF block can be removed – as you allude to, it is unnecessary. I will update the D7 module. The D8 module does not have such code.

alpha2zee’s picture

Assigned: Unassigned » alpha2zee
Status: Active » Closed (fixed)