1

Ok, most bizarre PHP error I've ever encountered.

I have a Joomla module that has a startup.php which includes several files:

...
require_once(SYS_PATH . 'json.php');
require_once(SYS_PATH . 'utf8.php');
...

On one deployment, this reveals an error that the utf8.php is clashing with another set of utf8 functions from a different module. That part makes sense.

The bizarre unexplained part is that I have a second deployment (the dev site) where this problem is not occurring. After debugging, I determined that the 'utf8.php' is not getting loaded at all. The require_once is simply not happening. BUT, if I try printing the return value of require_once, then it DOES include the file and reveal the exception.

// does NOT run any code in utf8.php
...
require_once(SYS_PATH . 'json.php');
error_log('loading utf8.php');
require_once(SYS_PATH . 'utf8.php');
...

-

// DOES run the code in utf8.php
...
require_once(SYS_PATH . 'json.php');
error_log( 'loading utf8.php' );
error_log( 'require returns ' . require_once(SYS_PATH . 'utf8.php') );
...

-

// does NOT run the code in utf8.php
...
require_once(SYS_PATH . 'json.php');
error_log("before include utf8.php");
$x= '' . require_once(SYS_PATH . 'utf8.php');
error_log($x); // prints "1"
error_log("after include utf8.php");

-

// DOES run the code in utf8.php
...
require_once(SYS_PATH . 'json.php');
error_log("before include utf8.php");
include_once(SYS_PATH . 'utf8.php');
error_log("after include utf8.php");

I literally just add or remove the "error_log" wrapper around the require_once function, and it starts working or stops working.

Does anyone have ANY insight into this??

Also: I have added error_log statements before and after this statement and within this and other required files, and they all show up in the log, and the page loads fine (when the require isn't happening on utf8 module). All file permissions are identical.

Linux 3.10.17 Apache 2.2.20 PHP 5.3.6

dataless
  • 388
  • 4
  • 9
  • What is the value of `SYS_PATH`? – Pattle Mar 04 '14 at 22:00
  • an absolute path: /var/websites/anonymized/htdocs/components/anonymized/utf8.php There are no symlinks involved in the path. It is verified to be the correct path because when I wrap the require with error_log(), the changes I'm making to that file take effect. – dataless Mar 04 '14 at 22:06
  • Hm, weird. Are you running any kind of opcode cache on dev, and if so, what happens if you disable that? – Wrikken Mar 04 '14 at 22:10
  • Yes, APC 3.1.9, but I've cleared it since then and no change. Also, I'm editing both files quite a bit with all the error_log statements, so the timestamps will have changed plenty, and the error_log(require_once) wrapper is still the determining factor for whether it happens or not. – dataless Mar 04 '14 at 22:20
  • I turned off APC (verified disabled from apc.php) and the problem is exactly as before. – dataless Mar 04 '14 at 22:33

1 Answers1

0

Figured it out. It was a plugin called "VQmod", which essentially rewrites source files into a temp directory, applying search/replace on the code. The require_once() statement was getting rewritten with other code. When I changed it enough that the search/replace could no longer apply, my original code would get executed.

I discovered it by adding a

log_error("... ".__FILE__)

which revealed it was being executed from within vqmod's cache. i.e. each time I edited the file, vqmod would see my changes and rewrite it into the cache, then execute the cache instead of the original.

dataless
  • 388
  • 4
  • 9