Hello,

When using 'customfield: PHP code' and declaring a function in the php code, I get the following error:

Fatal error: Cannot redeclare child_level() (previously declared in /var/www/jdbi/sites/all/modules/views_customfield/includes/views_customfield_handler_field_phpcode.inc(118) : eval()'d code:10) in /var/www/jdbi/sites/all/modules/views_customfield/includes/views_customfield_handler_field_phpcode.inc(118) : eval()'d code on line 23

If I put the function in a separate file a do a include of the file, I get the same error. Using the same code somewhere else in views, for example in the header, it works as it should

Comments

Isostar’s picture

Title: Cannot redeclare function when including function customfield PHP code » Cannot redeclare function when including function in customfield PHP code
infojunkie’s picture

Status: Active » Closed (works as designed)

The custom field code is evaluated once for each row in the view result, as opposed to the view header which is only evaluated once. I suggest placing your function in your own module.

chitraar’s picture

how to include user defined .inc file in a tpl file.

bis20’s picture

Just do following Technic:

Do it That way:

1- create your custom module [testmodule]
2- create testmodule.install file with following syntax:

<?php
// $Id:
/**
* Implementation of hook_install().
*/
function testmodule_install() {
  $filename = drupal_get_path('module','testmodule') . "/testmodule.code.inc";
}

3- Create testmodule.code.inc file & place your Custom function on it.
4- goto your view and place the following code in Header of view:

<?php
module_load_include('inc', 'testmodule', 'testmodule.code');
?>

5- finally check the loading of include file in your custom php field by following function :

if (module_load_include('inc', 'testmodule', 'testmodule.code') !== FALSE) {

}

do not forget to flush caches.

B&R
Bis20