note 109017 added to language.types.string

From: Date: Tue, 12 Jun 2012 23:04:38 +0000
Subject: note 109017 added to language.types.string
Groups: php.notes 
Request: Send a blank email to php-notes+get-188550@lists.php.net to get a copy of this message
Like "headden at karelia dot ru" (20-Jun-2009 12:43) and others, it would be great to print the return value of a function in a string, heredoc, etc. This workaround stores the function's computed result in a uniquely-named global, then returns the global's name for interpretation as part of the string. The function call embedded in the string simply displays the resulting value. <?php function someFunction ($t) { global $someFunction_return_value; $someFunction_return_value = $t*$t + $t; return 'someFunction_return_value'; } $x = 23; $y = 7; header("Content-type: text/plain"); print <<<__TXT__ Value of $x^2 + $x is {${someFunction($x)}} Value of $y^2 + $y is {${someFunction($y)}} __TXT__; ?> ---- Server IP: 69.147.83.197 Probable Submitter: 76.218.80.143 ---- Manual Page -- http://www.php.net/manual/en/language.types.string.php Edit -- https://master.php.net/note/edit/109017 Del: integrated -- https://master.php.net/note/delete/109017/integrated Del: useless -- https://master.php.net/note/delete/109017/useless Del: bad code -- https://master.php.net/note/delete/109017/bad+code Del: spam -- https://master.php.net/note/delete/109017/spam Del: non-english -- https://master.php.net/note/delete/109017/non-english Del: in docs -- https://master.php.net/note/delete/109017/in+docs Del: other reasons-- https://master.php.net/note/delete/109017 Reject -- https://master.php.net/note/reject/109017 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#188550) next »