0

I activated the PHP filter and it works fine, except when I declare a function. I keep getting the following error.

Fatal error: Cannot redeclare test_function_test() (previously declared in /web/htdocs/www.example.org/home/modules/php/php.module(80) : eval()'d code:3) in /web/htdocs/www.example.org/home/modules/php/php.module(80) : eval()'d code on line 1034

First, I tried with the following code.

function test_function_test() {
  echo "test";
}

Then, I tried using function_exists().

if (!function_exists('test_function_test')) {
  function test_function_test() {
    echo "test";
  }
}

In both cases, I keep getting the same error message.

How can I use a define a function in the code passed to the PHP filter, without getting this error?

  • Please note the PHP module is removed in Drupal 8 because it is dangerous. There is certainly a better way to accomplish your goals without it. – cilefen Dec 28 '16 at 0:38
  • As I said: it's Drupal 7.53 – Tormy Van Cool Dec 28 '16 at 13:14
0

You can try adding declaration of the function in your module. But call it using php filter.

Moreover, in this case you will be able to edit code of your function with less chance of break the site.

  • the code is written into a node – Tormy Van Cool Dec 28 '16 at 13:14

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.