S
S
santavits2018-04-06 19:20:54
PHP
santavits, 2018-04-06 19:20:54

Why such an error with an array?

Help, I'm getting this error
Fatal error: Cannot use object of type stdClass as array in
Request I'm doing
$params = array(
'owner_id' => $group,
'offset' => "1",
'v' => "5.47" ,
'access_token' => $token
);
$array = send_vk_api("wall.get", $params);
//echo '';
//print_r($array);
$post_type = $array->response[1]->post_type;
$ads = $array->response[1]->marked_as_ads;
$id = $array->response[1]->id;
Here is what I get in response

stdClass Object ( [response] => stdClass Object ( [count] => 3847 [items] => Array ( [0] => stdClass Object ( [id] => 18005 [from_id] => -39209729 [owner_id] => -39209729 [date] => 1506952657 [marked_as_ads] => 0 [post_type] => post [text] => Женские футболки VOGUE http://ali.pub/1vi5l9 [attachments] => Array ( [0] => stdClass Object ( [type] => photo [photo] => stdClass Object ( [id] => 456239045 [album_id] => 248105613 [owner_id] => -39209729 [user_id] => 100 [photo_75] => https://pp.userapi.com/c837334/v837334105/61a12/UpjKkImGIHA.jpg [photo_130] => https://pp.userapi.com/c837334/v837334105/61a13/RJIgfvF6rCo.jpg [photo_604] => https://pp.userapi.com/c837334/v837334105/61a14/EAEam77Mhhg.jpg [photo_807] => https://pp.userapi.com/c837334/v837334105/61a15/TQLE1SVJRwo.jpg [photo_1280] => https://pp.userapi.com/c837334/v837334105/61a16/DWKY1fOP6uY.jpg [width] => 1000 [height] => 948 [text] => #Одежда #Стиль #Вкусно #НЕдорого #Футболка #Женская #ЖенскаяОдежда http://ali.pub/1vi5l9 [date] => 1506694328 [access_key] => ea1f90bf08ab292d93 ) ) [1] => stdClass Object ( [type] => photo [photo] => stdClass Object ( [id] => 456239046 [album_id] => 248105613 [owner_id] => -39209729 [user_id] => 100 [photo_75] => https://pp.userapi.com/c837334/v837334105/61a1b/55TBQWjZ__M.jpg [photo_130] => https://pp.userapi.com/c837334/v837334105/61a1c/2oG2pARQ_CI.jpg [photo_604] => https://pp.userapi.com/c837334/v837334105/61a1d/O2F5s8dXydo.jpg [photo_807] => https://pp.userapi.com/c837334/v837334105/61a1e/KdxlMICySUg.jpg [width] => 733 [height] => 736 [text] => #Одежда #Стиль #Вкусно #НЕдорого #Футболка #Женская #ЖенскаяОдежда http://ali.pub/1vi5l9 [date] => 1506694329 [access_key] => 6334c50329baf10bda ) ) [2] => stdClass Object ( [type] => photo [photo] => stdClass Object ( [id] => 456239047 [album_id] => 248105613 [owner_id] => -39209729 [user_id] => 100 [photo_75] => https://pp.userapi.com/c837334/v837334105/61a23/LiAHfSEtw5g.jpg [photo_130] => https://pp.userapi.com/c837334/v837334105/61a24/4vaz-_NSVTE.jpg [photo_604] => https://pp.userapi.com/c837334/v837334105/61a25/iDIaB_W3vQI.jpg [photo_807] => https://pp.userapi.com/c837334/v837334105/61a26/ODnIgmWBf8I.jpg [photo_1280] => https://pp.userapi.com/c837334/v837334105/61a27/P-Ry7-HPbEc.jpg [width] => 1000 [height] => 1000 [text] => #Одежда #Стиль #Вкусно #НЕдорого #Футболка #Женская #ЖенскаяОдежда http://ali.pub/1vi5l9 [date] => 1506694329 [access_key] => eab27ff3610cda2900 ) ) [3] => stdClass Object ( [type] => photo [photo]  => stdClass Object ( [count] => 0 [can_post] => 1 ) [likes] => stdClass Object ( [count] => 174 [user_likes] => 0 [can_like] => 1 [can_publish] => 1 ) [reposts] => stdClass Object ( [count] => 24 [user_reposted] => 0 ) ) ) ) )
Fatal error: Cannot use object of type stdClass as array in

These values
$post_type = $array->response[1]->post_type;
$ads = $array->response[1]->marked_as_ads;
$id = $array->response[1]->id;

already getting this error Fatal error: Cannot use object of type stdClass as array in

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question