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

Popular posts from this blog

java - UnknownEntityTypeException: Unable to locate persister (Hibernate 5.0) -

python - ValueError: empty vocabulary; perhaps the documents only contain stop words -

ubuntu - collect2: fatal error: ld terminated with signal 9 [Killed] -