php - Why does my methods have no output? -


i creating googlemapapi class. found in net thought not me. decided build own.

actually thats not first class , used it....

here got:

class gmapi{      private $apikey;     private $from;;      public function gmapi(){          $this->apikey = google_api_key;     }      public function setfrom($string){          $this->from = $this->preparestring($string);     }       public function getdistance($type="meter"){          echo $this->from; //output empty         echo $type;       //outputs: meter     } } 

now have other php file content

$gmapi = new gmapi(); $gmapi->setfrom('new york'); $gmapi->getdistance();  //output: meter //expacted output: new yorkmeter 

i have tried this

public function setfrom($string){     echo $string;     $this->from = $string; } 

but still no result. not with

public function setfrom($string="foobar"){     echo $string;     $this->from = $string; } 

what doing wrong ?!?!?

edit: shorted post have better overview

full code

class.controller.php

class.gmapi.php

(according comments changed var's not have reserved var's in use)

this code creates new properties on fly, should changed example below

$this->gmapi->setfromaddress   =   "new york"; $this->gmapi->settoaddress     =   "boston";  

this code calls setters

$this->gmapi->setfromaddress("new york"); $this->gmapi->settoaddress("boston");  

happy coding!


Comments

Popular posts from this blog

java - How to specify maven bin in eclipse maven plugin? -

single sign on - Logging into Plone site with credentials passed through HTTP -

php - Why does AJAX not process login form? -