php - How to reference an object from inside a private function -


i using mixpanel's php api , want call mp->track.

in case, mp->track defined object in mixpanel library, called via require(mixpanel.php).

typically, work fine:

require ('mixpanel-php/lib/mixpanel.php'); $mp = mixpanel::getinstance("xxx"); $mp->track('session'); 

however, want call mp->track() within private function, following gives object not defined error:

require ('mixpanel-php/lib/mixpanel.php'); $mp = mixpanel::getinstance("xxx")  private function startsession() {  $mp->track('session');  } 

this approach; if define

$mp = mixpanel::getinstance("xxx"); 

somewhere in class; should use as

$this->mp->track('session'); 

so code should

<?php   require ('mixpanel-php/lib/mixpanel.php');    class myclass {     protected $mp;     public function __construct() {       $this->mp = mixpanel::getinstance("xxx");     }      private function startsession() {       $this->mp->track('session');     }    } ?> 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -