api - Understanding PHP External Classes -


i want access method external class, within file.

i have external class, let's say:

external/file.php

class externalclass {   private $myclient;    const constant = 'some/path';    public function _constructor($myclient) {     $this->myclient = $myclient;   }    public function getsome($information) { // need access function     $data = new stdobject();     $data->information = $information;     $result = $this->myclient->post(       self::constant,       $data     );     return($result['code'] == 200 ? json_decode($result['body']) : false);   }    public static function instance($settings) {     return new externalclass(new myclient($settings['externalclass']['host']));   }  } 

... reference class in file.

internal/file.php

include_once('external/file.php');  $externalclassinstance = externalclass::instance($settings); // line 3 $externalclass = new externalclass(); // line 4 $externalclassgetsome = $externalclass->getsome($information);  // line 5 

the problem is, i'm not sure if i'm correctly referencing external methods inside internal file.

is "line 3" necessary?

also, addition of line 5 code breaks code after it.

firstly don't know why need line 3. secondly seem have answer right there

include_once('external/file.php'); $externalclass = new externalclass(); // line 4 $externalclassgetsome = $externalclass->getsome($information); 

Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -