I am going to explain a case that may seem a little rare but perhaps it may be useful for other people involved in something similar.

In a project where I work we use APC to optimize code execution and at one point had a problem with the PHP interpreter to evaluate the following line:

$vars['styles'] .= $vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], '');

At the runtime $vars ['styles'] will be destroyed if variable_get('conditional_styles_'. $ GLOBALS ['theme'],'') was an empty string.

This has no logic, I know, and I've tested with examples (assign variables at the same time the result is concatenated to another variable) and no problems are found.

More data, this error did not occur with the following equivalent code:

$vars['conditional_styles'] = variable_get('conditional_styles_' . $GLOBALS['theme'], '');
$vars['styles'] .= $vars['conditional_styles'];

Obviously this was an error of interpretation of the code and doing more tests I saw that this did not occur in an environment exactly the same but without the APC.

Then it was a problem of the PHP code optimizing that APC makes.

Well, completely disabling the APC (apc.enable = 0) and re-enable the interpretation of the first code that I posted was successful and I was unable to reproduce this bug again.

So the conclusion is a mistake of the APC, with some given internal execution circumstances, to optimize the code that I firstly comment (probably APC developers might know it may be due).

We've just updated PHP from 5.14 to 5.17 and APC 3.1.5 to 3.1.7 and we don't know if this bug will be corrected with those version changes but...

I roll a patch, if you do not mind applying, the logic of the program is exactly the same and would have two advantages (the second is potential):

- The code is easier to read.
- Facilitate the work of code optimizers.

Finally I want to add that I've been doing a search on the code of other modules and is not usually assign values to variables, while concatenating to a third variable, all in one line. With something like:

find -L -type f \( -name "*.module" -o -name "*.inc" \) -exec egrep -e '\.=.+=[^>]' {} \;

Thank you very much for your understanding. I told you in advance that a bug is hard to reproduce but by the time I could I am 100% sure that with the patch I propose the problem does not occur.

CommentFileSizeAuthor
conditional_styles.module.patch1.46 KBdaniels____
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

markus_petrux’s picture

Status: Needs review » Reviewed & tested by the community

The patch is simple, makes the code more readable and fixes the issue. Thanks!

JohnAlbin’s picture

Title: $vars['styles'] is destroyed, rare bug with APC. » $styles is destroyed by rare bug with APC
Status: Reviewed & tested by the community » Fixed

Status: Fixed » Closed (fixed)

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