This code works and there may be better methods to achieve the thing,but my questions are ,
Is there any specific term for passing like this ? (as with anonymous functions ),
is this an acceptable practice ? ,
is it against standards ?
<?php
// suppose the only way i can retrieve the content is by using this function
//like wordpress equivalent of the_content()
function mycontent()
{
$Original_content="oldcontent";
return $Original_content;
}
//instead of ---> echo $Original_content."facebook,twitter code";
//if i define a new function
function social_share($content)
{
$added_social=$content;
$added_social.=" + facebook,twitter code...";
echo $added_social;
}
//function call
social_share(mycontent());
?>
thanks in advance 🙂
You’re not passing a function. You’re passing the result of one function call directly to another as an argument. ‘passing a function’ implies that the ‘parent’ function will be calling the ‘child’ function at some point. IN this case, social_share does NOT invoke mycontent() at all – that’s done long before social_share even executes.
That being said, if you had something like this:
then you would be invoking one function from another by passing it as an argument. In this case, you’d get “hello” printed out by your little custom
my_echofunction, without ever having writtenmy_echo('hello');.