Jump to content

Unexpected FileCompiler behaviour with "require"


noodles
 Share

Recommended Posts

Hey there,

we recently took over a ProcessWire project from a different agency, since the client wanted to work with us now.

We experienced a weird behaviour and I hope someone can explain it! ? The former agency used a ZebraForm class for formular building which worked/works fine on the clients server, but not on our staging system.

The code within ZebraForm is:

require rtrim(dirname(__FILE__), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'languages/' . strtolower(trim($language)) . '.php';

The FileCompiler converts it to:

require(\ProcessWire\wire('files')->compile(rtrim(dirname(\ProcessWire\wire("config")->paths->root . 'site/templates/assets/zebra-form/Zebra_Form.php'),array('includes'=>true,'namespace'=>true,'modules'=>true,'skipIfNamespace'=>true)), DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'languages/' . strtolower(trim($language)) . '.php');

Error message:

Warning: rtrim() expects parameter 2 to be string, array given in /var/www/[...]/site/assets/cache/FileCompiler/site/templates/assets/zebra-form/Zebra_Form.php on line 1076

So to check what went wrong, we changed the syntax within the ZebraForm class to:

require rtrim(
	dirname(__FILE__),
	DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'languages/' . strtolower(trim($language)
) . '.php';

So basically, we put it in new rows... No big deal, no magic. ?

The FileCompiler now converts it to:

require rtrim(
	dirname(\ProcessWire\wire("config")->paths->root . 'site/templates/assets/zebra-form/Zebra_Form.php'),
	DIRECTORY_SEPARATOR) . DIRECTORY_SEPARATOR . 'languages/' . strtolower(trim($language)
) . '.php';

 

Et voila, it works now!

Does anyone have any idea why this happened? Asking out of curiosity! 

Thank you!
Niko

Link to comment
Share on other sites

While rare, there are some situations where the FileCompiler may not convert code correctly.  If you are using an older version of PW it may have already been resolved in a newer version.

Besides, you could probably simplify that code to something more simple.  Adjust this accordingly with your language variable if needed:

Quote

require($config->paths->templates."path/to/file.php");

 

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...