javascript - PHP passing params to new string (learning) -
still learning , still many questions here few go. doing javascript -> php conversion , want make sure these practices correct. $dailyparams->$calories = $calories; correct line? again!
javascript
dailyparams.create4 = function(/*double*/ calories, /*double*/ carbpercent, /*double*/ sodium, /*double*/ actparam) { if (calories < 0.0) calories = 0.0; if (carbpercent < 0.0) carbpercent = 0.0; if (carbpercent > 100.0) carbpercent = 100.0; if (sodium < 0.0) sodium = 0.0; if (actparam < 0.0) actparam = 0.0; var dailyparams = new dailyparams(); dailyparams.calories = calories; dailyparams.carbpercent = carbpercent; dailyparams.sodium = sodium; dailyparams.actparam = actparam; return dailyparams;} dailyparams.create2 = function(/*intervention*/ inter, /*baseline*/ base) { var dailyparams = new dailyparams(); dailyparams.calories = inter.getcalories(); dailyparams.carbpercent = inter.getcarbinpercent(); dailyparams.sodium = inter.getsodium(); dailyparams.actparam = inter.getact(base); return dailyparams;
}
php
public function create4($calories, $carbpercent, $sodium, $actparam) { if ($calories < 0.0) $calories = 0.0; if ($carbpercent < 0.0) $carbpercent = 0.0; if ($carbpercent > 100.0) $carbpercent = 0.0; if ($sodium < 0.0) $sodium = 0.0; if ($actparam < 0.0) $actparam = 0.0; $dailyparams = new $dailyparams(); $dailyparams->$calories = $calories; $dailyparams->$carbpercent = $carbpercent; $dailyparams->$sodium = $sodium; $dailyparams->$actparam = $actparam; return $dailyparams; } public function create2($inter,$base) { $dailyparams = new $dailyparams(); $dailyparams->$calories = $inter->getcalories(); $dailyparams->$carbpercent = $inter->getcarbinpercent(); $dailyparams->$sodium = $inter->getsodium(); $dailyparams->$actparam = $inter->getact($base); return $dailyparams; }
dailyparams
classname, lose $
:
$dailyparams = new dailyparams();
same property names calories
:
$dailyparams->calories = $calories;
Comments
Post a Comment