0

hello

i had stumbled on kinda simple problem but i can't get and idea what could be wrong:

        function zabbixGraphGetId($HostName, $Name,$zabbixData) {

            try {

                $api = new ZabbixApi(...$zabbixData);

            } catch (Exception $e) {
                // Exception in ZabbixApi catched
                echo $e->getMessage();
            }
            $GetGraphId = $api->graphGet(array(
                'output' => 'extend',
                'filter' => array('host' => $HostName),
                'search' => array('name' => $Name)
            ));
            $ReturnGraphId = $GetGraphId['0']->graphid;

            return $ReturnGraphId;
        }

Thats my function in symfony and i want to get from array $GetGraphId value of only graphid. Point is after i call this function i get this error: Warning: Attempt to read property "graphid" on array But if i'll return whole array($GetGraphId) i get this:

array:2 [
  0 => array:19 [
    "graphid" => "some id"
    "name" => "Network traffic on tun0"
    "width" => "900"
    "height" => "200"
    "yaxismin" => "0"
    "yaxismax" => "100"
    "templateid" => "0"
    "show_work_period" => "1"
    "show_triggers" => "1"
    "graphtype" => "0"
    "show_legend" => "1"
    "show_3d" => "0"
    "percent_left" => "0"
    "percent_right" => "0"
    "ymin_type" => "1"
    "ymax_type" => "0"
    "ymin_itemid" => "0"
    "ymax_itemid" => "0"
    "flags" => "4"
  ]

so there is graphid value yet i still cant get it, i would really appreciate any clues/ideas/solutions thanks!

2
  • The warning says it: Attempt to read property "graphid" on array. You cannot access graphid with object->property notation. Use this line instead: $ReturnGraphId = $GetGraphId['0']['graphid']; Commented Jan 27, 2022 at 11:17
  • well that solved my problem xd. i cant mark comment as solution. Will you answer to this, ill mark it as solved. Thanks! Commented Jan 27, 2022 at 11:20

1 Answer 1

1

The warning says it: Attempt to read property "graphid" on array. You cannot access graphid with object->property notation. Use this line instead:

$ReturnGraphId = $GetGraphId['0']['graphid']; 
Sign up to request clarification or add additional context in comments.

1 Comment

$GetGraphId[0]['graphid']; is better, acces index with numeric if is key array numeric not with string

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.