Active
Project:
Views Custom Field
Version:
6.x-1.x-dev
Component:
Code
Priority:
Major
Category:
Support request
Assigned:
Unassigned
Reporter:
Created:
4 Sep 2010 at 09:21 UTC
Updated:
8 Mar 2011 at 15:38 UTC
I can insert the following function in a block directly, using the PHP filter, but if inserted in Views Custom Field displayed in a block it bombs with a parse error:
<?php
function writeName()
{
echo "Druplicate";
}
echo "My name is ";
writeName();
?>
Parse error: syntax error, unexpected T_ECHO, expecting '{' in /usr/local/www/apache22/data/includes/common.inc(1695) : eval()'d code on line 4
I've used VCF for other PHP before with no problem, but anytime I try to define a function it fails.
Comments
Comment #1
eL commentedMay be, I have same problem. But if I declare a function in PHP Custom Field, my server crashed with error 500.
Comment #2
eL commentedin DEV same problem
Comment #3
eL commentedIt looks like minor problem, because we can define our function in own modul and use it in custom field. BUT, if we need values from concrete fields from our view, we are screwed. And this is very usefull ie. for Popup module...
Comment #4
casey commentedThe code is run for every row; your function is redefined for every row. If you want functions in your code you have to ensure they don't get redefined. You could use function_exists or the $static variable to do so.
Comment #5
eL commentedcasey - it was a good hint!
Anyway, we can declare function in own helper module and pass variables through function arguments.
Comment #6
tekken commentedthanks casey.