Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
Hi if i declare a function in the setup code and then use the view with this field inside another view with the Views field view module then i geht the error Fatal error: Cannot redeclare myfunction() (previously declared in ...\sites\all\modules\views_php\plugins\views\views_php_handler_field.inc(117) : runtime-created function:1) in ...\sites\all\modules\views_php\plugins\views\views_php_handler_field.inc(117) : runtime-created function on line 1
There seems to be an namespace conflict with the runtim-created function that redeclared themself in this case.
Comments
Comment #1
darshanchoudhary CreditAttribution: darshanchoudhary commentedHi,
Did you find any solution for this..I am also getting the same error when i declare a function in Output code.
Comment #2
tfranz CreditAttribution: tfranz as a volunteer commentedI had the same problem when declaring a function in the field "Setup Code".
My solution was to NOT "Use setup code" and instead writing everything into "Filter code".
(Interesting: the error appeared after a while and not directly. Could be like something like a caching-problem? I switched of caching, but the error still persisted until i disabled the "Setup Code".)
Comment #3
StephenN CreditAttribution: StephenN commentednot sure of the root cause but the simple fix is to wrap your function definition inside an if(!function_exists('name_of_function')){ statement