Integrating 2 API's into 1 php class (OOP newbie) -
i want integrate google analytics , marchex (call tracking system) call analytics api's pull custom reports conversion rates , sort of thing. very, new world of object oriented programming, , think need guidance getting off ground. critique on constructor before move on further. doing right or what?
<?php require_once("gapi.class.php"); require_once("xmlrpc.inc"); class garchex { private $marchex_credentials = array(), $ga_credentials = array(); private $marchex_account, $ga_account; public function __construct($marchex_credentials,$ga_credentials) { assert(is_array($marchex_credentials)); assert(is_array($ga_credentials)); //setup marchex stuff $this->marchex_credentials = $marchex_credentials; $this->marchex_account = new xmlrpc_client("/api/xmlrpc/1", "api.voicestar.com"); $this->marchex_account->setcredentials($marchex_credentials[0],$marchex_credentials[1]); //google analytics stuff $this->ga_credentials = $ga_credentials; $this->ga_account = new gapi($ga_credentials[0],$ga_credentials[1]); } // __construct } // class garchex ?>
you assigned non-static variable using ->$ syntax, wasn't ok. here's fixed proposal:
<?php // better use require_once, in case loads file again require_once( "gapi.class.php" ); require_once( "xmlrpc.inc" ); class garchex { private $marchex_credentials = array(), $ga_credentials = array() ; public function __construct( $marchex_credentials, $ga_credentials ) { // check, if values fine assert( is_array( $marchex_credentials ) ); assert( is_array( $ga_credentials ) ); //setup marchex stuff $this->marchex_credentials = $marchex_credentials; $marchex_account = new xmlrpc_client("/api/xmlrpc/1", "api.voicestar.com"); $marchex_account->setcredentials($marchex_credentials[0],$marchex_credentials[1]); // google analytics stuff // no $ access non-static ivars $this->ga_credentials = $ga_credentials; // black hole: local variable assigned. // won't able access outside method. $ga_account = new gapi($ga_credentials[0],$ga_credentials[1]); } // __construct } // class garchex // better drop closing php tag
Comments
Post a Comment