caffeineJunkie
Technical User
I use "heredoc" syntax often and lately have been looking for a way to process a variable that may or may not be "set" inside the output. By using 'create_function' you can alias a function and get this functionality.
References:
create-function
heredoc
Hope this is helpful.
cJ
Code:
$error = array();
$error['email'] = 'Bad';
$listError = create_function('$field',
'global $error;'.
'return (isset($error[$field]))? $error[$field] : "Good";');
// the following tests a simple function return
echo <<<EOF
<p><pre>
This is a test of simple function return inside heredoc
OK the input for phone was {$listError('phone')}
And the input for email was {$listError('email')}
heredocs rule...
</pre></p>
EOF;
create-function
heredoc
Hope this is helpful.
cJ