Get Weather - Step 4 - Enhancing encapsulation


/ Published in: PHP
Save to your folder(s)



Copy this code and paste it in your HTML
  1. class WeatherService{
  2.  
  3. public function WeatherService(){
  4. //some initialization...
  5. }
  6.  
  7. public function getWeatherInfo($city, $method=""){
  8.  
  9. $res = shell_exec("./getWdr.sh {$city}");
  10.  
  11. if ($methos=="CL")
  12. return convertFrToC($res);
  13.  
  14. return $res;
  15. }
  16.  
  17. public static function convertFrToC($val){
  18. return (($val+40)*5/9)-40;
  19. }
  20.  
  21.  
  22. }
  23.  
  24.  
  25. //now it can also be used independently of the rest of the WeatherService
  26. //functions and main purpose...
  27.  
  28. $c = WeatherService::convertFrToC(22);

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.