php - Converting Procedural code to a class file -


i trying build class file. started out basic proceedural code working fine:

the code here calculate minimum , maximum longitude , latitude give center point lon , lat , radius of 100 miles or 160.934 kilometers.

        $lat = 32.373591;    //location latitude     $lon = -88.743598;   //location longitude      $r = (160.934/6371);    //radius distance in km     $latmin = $lat - $r;  //calculate minmum latitude     $latmax = $lat + $r;  //calculate maximum latitude      $latt = asin(sin($lat)/cos($r));  //don't know calculation      //$lontri = arccos((cos($r)-sin($latt)*sin($lat))/(cos($latt)*cos($lat));      $lontri = asin(sin($r)/cos($lat));      $lonmin = $lon - $lontri;     $lonmax = $lon + $lontri; //calculate min , max longitude       echo $lat . " latitude<br><br>";     echo $lon . " longitude <br><br>";     echo $r . " r <br><br>";     echo $latmin . " latitude min<br><br>";     echo $latmax . " latitude max<br><br>";     echo $latt . " latititude total <br><br>";     echo $lontri . " lontri <br><br>";     echo $lonmin . " lon min<br><br>";     echo $lonmax . " lon max<br>"; 

i want convert class file in php. not sure work want make sure class can reproduce calculation properly. class file looking

 class nextcitycal {  //location latitude public $lat;  //location longitude public $lon;  //radius distance in km public $r = 0.0252603986815257;  //calculate minmum latitude public $latmin = $lat - $r;  //calculate maximum latitude public $latmax = $lat + $r;  //don't know calculation public $latt = asin(sin($lat)/cos($r));   public $lontri = asin(sin($r)/cos($lat));  //calculate min , max longitude $lonmin = $lon - $lontri; $lonmax = $lon + $lontri;  //set latitude value pulled database public function setlat($lat){     $this->lat = $lat; }  //rerurn latitude processing public function getlat(){     return $this->lat; } //set longitude valuse pulled database public function setlon($lon){     $this->lon = $lon; }  //calculate minimum latitude public function callat($lat, $r){     if(!$lat){         $this->callat = $lat - $r;         return $this->callat;     } }   } 

my question

$latmin = $lat - $r; 

in proceedural code straight math. in class file converted

    //calculate minimum latitude public function callat($lat, $r){     if(!$lat){         $this->callat = $lat - $r;         return $this->callat;     } } 

will return calculated results want? if no how go adding variables in class file?

it's best keep scope no greater it's required usage better readability , resource management. can use private or protected properties (variables) if you're not setting or reading them outside class. , can use locals inside of methods stand-alone function. can use constructor method (__construct)to initialize properties instead of doing the declaration - you'll have 1 place see initializations.


Comments

Popular posts from this blog

java - WrongTypeOfReturnValue exception thrown when unit testing using mockito -

php - Magento - Deleted Base url key -

android - How to disable Button if EditText is empty ? -