There is a class in which a function, and in it an object of $photo Please teach how to “read” this object outside of a function and a class ?!

 <?php require_once '../sys/config.php'; class Model_VK { public $access_token, $v; const API = 'https://api.vk.com/method/'; public function __construct($access_token, $v){ $this->access_token = $access_token; $this->v = $v; } public function uploadImage($file, $group_id = null, $album_id = null){ list($params['group_id'], $params['album_id']) = [$group_id, $album_id]; $upl = $this->vk('photos.getUploadServer', $params)->response->upload_url; if (isset($upl)) { $upload = json_decode($this->curl($upl, ['file1' => new CURLFile($file)])); if (isset($upload->server)) { $photo = $this->vk('photos.save', [ 'server' => $upload->server, 'photos_list' => $upload->photos_list, 'album_id' => $album_id, 'hash' => $upload->hash, 'group_id' => $group_id ]); //print "<pre>"; print_r($photo); return $photo; } - ПРОБОВАЛ СЮДА } - ПРОБОВАЛ СЮДА } - ПРОБОВАЛ СЮДА public function vk($method, $params){ list($params['access_token'], $params['v']) = [$this->access_token, $this->v]; return json_decode($this->curl(self::API . $method, $params)); } public function curl($url, $params = false) { $ch = curl_init($url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); if (isset($params)) { curl_setopt($ch, CURLOPT_POST, 1); curl_setopt($ch, CURLOPT_POSTFIELDS, $params); } $upd = curl_exec($ch); curl_close($ch); return $upd; } } $new = new Model_VK(mc_decrypt($_SESSION['UserInfo']['master_token'], ENCRYPTION_KEY), $System['api']['version']); $new->uploadImage($ThisImg, $GroupID, $AlbumID); // адрес фото / id группы / id альбома print "<pre>"; print_r($photo); 
  • return $photo; - Igor
  • no matter how it works%) I tried to write return $ photo immediately after // print "<pre>"; print_r ($ photo); nothing is displayed, if outside the class you try to call the object ... - Dimastik86

1 answer 1

it turns out everything is simple, it was necessary to replace

 $new->uploadImage($ThisImg, $GroupID, $AlbumID); 

on

 $photo = $new->uploadImage($ThisImg, $GroupID, $AlbumID); 

and work with the array / object $ photo