此代码的工作,可能有更好的方法来实现的事情,但我的问题是,传递函数作为参数传递给另一个函数
有没有经过任何这样的特定术语?(与匿名函数),
这是一个可以接受的做法? ,
是针对标准吗?
<?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());
?>
在此先感谢:)
你有某种非常基本的...控制器也许,但它是相当最小。从那里工作,并建立它。看看它是否有效,然后可能作为奖励检查,如果它扩大。 – stefgosselin
你正在做什么是完全正常的,但你实际上并没有经过“一个函数作为参数传递给另一个函数”。 social_share(mycontent())首先评估mycontent(),该函数的结果被传递给社交共享,而不是函数mycontent。但这只是术语,代码本身很好。 我不认为你在做什么有一个特殊的术语。 它只是简写:$ tmp = mycontent(); social_share($ TMP);你的代码是可取的,因为你没有创建无用的变量。 – rx80