我想在当前日期添加天数:我使用以下代码:
$i=30;
echo $date = strtotime(date("Y-m-d", strtotime($date)) . " +".$i."days");
Run Code Online (Sandbox Code Playgroud)
但是没有得到正确的约会我得到了这个: 2592000
请建议.
我知道你可以将函数的返回值赋给变量并使用它,如下所示:
function standardModel()
{
return "Higgs Boson";
}
$nextBigThing = standardModel();
echo $nextBigThing;
Run Code Online (Sandbox Code Playgroud)
所以有人请告诉我为什么以下不起作用?或者它还没有实现?我错过了什么吗?
class standardModel
{
private function nextBigThing()
{
return "Higgs Boson";
}
public $nextBigThing = $this->nextBigThing();
}
$standardModel = new standardModel;
echo $standardModel->nextBigThing; // get var, not the function directly
Run Code Online (Sandbox Code Playgroud)
我知道我可以这样做:
class standardModel
{
// Public instead of private
public function nextBigThing()
{
return "Higgs Boson";
}
}
$standardModel = new standardModel;
echo $standardModel->nextBigThing(); // Call to the function itself
Run Code Online (Sandbox Code Playgroud)
但是在我的项目中,存储在类中的所有信息都是预定义的公共变量,除了其中一个,需要在运行时计算值.
我希望它一致,所以我或任何其他使用此项目的开发人员必须记住,一个值必须是函数调用而不是var调用.
但是不要担心我的项目,我主要想知道为什么PHP的解释器中的不一致? …