Like it says in the title.

I am trying to analyse performance on the home page of a site, and have noticed this error string being output in the content of a cached js file. E.g. the contents of js_a89adsd9f0d9d0adaddsfd987 (or whatever) is the above PHP error message.

CommentFileSizeAuthor
#16 devel-644716-16.patch624 bytesgapple
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

srobert72’s picture

Subscribing. I have same error.

Leo Pitt’s picture

A bit of additional info on my bug. The problem was intermittent, mostly the js file would be okay, but occasionally, maybe 1 in four times (if I remember correctly) this error would occur.

henrrrik’s picture

This pops up in our error logs too. RHEL5 box running PHP 5.1.6.

davividal’s picture

Same problem here.

I'm using normal cache option and if I clear the cache, the error is gone in the first page access. After that, the problem comes back.

huntsinger’s picture

Same problem here. Its strange because sometimes the t() function is there and sometimes it isn't. If I add the t() function to performance.module it will work for a time and the problem goes away. Wait a little while and then we get the error, cannot redeclare funtion t()

Devel is up to date - Devel 6.x-1.18

from apache2 error.log

[Tue Dec 22 10:42:13 2009] [error] [client ] PHP Fatal error: Call to undefined function t() in /sites/all/modules/devel/performance/performance.module on line 167

kostajh’s picture

Same problem here.

Additionally, I only see the error message on the home page of the site when using Chrome or IE 7, but not with Safari and Firefox.

viridisweb’s picture

Same problem here. For me it happens on home page and also when using the autocomplete on a finder form.

Additionally, it seems to only happen when cache is on.

gapple’s picture

Status: Active » Needs review

As noted in the documentation for common.inc, where t() is defined:

Common functions that many Drupal modules will need to reference.

The functions that are critical and need to be available even when serving a cached page are instead located in bootstrap.inc.

Therefore t() is never defined for cached pages, as it is assumed that any cached pages have everything to be output already translated.

The simplest solution would be to remove the t() calls; I don't think 'Yes' and 'No' are a priority to translate, especially for developers.

Otherwise, a check if t() is defined could be used to create a dummy function, which seems excessive for just two calls

if(!function_exists('t')){
  function t($text){
    return $text;
  }
}

or run the same line of code without t()

if(function_exists('t')){
  $anon = (!empty($data['anon'])) ? t('Yes') : t('No');
}
else{
  $anon = (!empty($data['anon'])) ? 'Yes' : 'No';
}

However, I could foresee some people getting confused if their output mysteriously changes from translated to untranslated, so would think consistently untranslated would be the best option.

RAFA3L’s picture

Same problem here...

dogbertdp’s picture

I've encountered this issue as well.

subscribing

dicreat’s picture

subscribing

Chris Einkauf’s picture

subscribing

Leo Pitt’s picture

@gapple #8

That seems like a pretty sensible solution to me, in the short term at least.

One suggestion, why not pass a value that is language-independent. E.g. Pass a simple boolean "1" / "0", or "TRUE" / "FALSE" instead of "Yes" / "No"?

Any functions which test the value can then use t() to output a human-readable string.

It seems to me that the fundamental problem is that the flag is being treated as output for human eyes, when really it's programming flag..

Make sense?

Leo Pitt’s picture

Sorry, double post, see above.

kbahey’s picture

Status: Needs review » Needs work

Can someone create a real patch, so others can apply and review?

gapple’s picture

Status: Needs work » Needs review
FileSize
624 bytes

Here's the simplest patch to just remove t() calls

kbahey’s picture

Version: 6.x-1.18 » 6.x-1.x-dev
Status: Needs review » Fixed

Thanks, I committed this patch to both the 6.x and 7.x -dev branches.

davividal’s picture

After *much* tests, it turns out that it seems that I was using cache 2 times: Drupal-side and server (lighttpd) side.

So, I was getting a page compressed 2 times, but my browser only decompressed it 1 time.

Disabling Drupal cache solved this issue for me.

Status: Fixed » Closed (fixed)

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