Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

function returns inside heredoc

Status
Not open for further replies.

caffeineJunkie

Technical User
Jan 17, 2008
2
US
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.

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;
References:
create-function
heredoc

Hope this is helpful.
cJ
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top