0

Why is my code saying that $publishRequest is undefined. it is really defined in the array

this is just a part of my code but this part is the part where the problem is hiding

already tried above the array:

php

$publishRequest = array()

if($status1=="up") {
    $publishRequest = array(
        "instance_id" => INSTANCE_ID,
        "name" => INSTANCE_NAME,
        "group" => INSTANCE_GROUP,
        "description" => "Running on Controller.Ligowave.com",
        "contents" => array(
            array(
                "name" => "Status",
                "contents" => array(
                    array(
                        "icon" => "information",
                        "type" => "label",
                        "title" => $name1,
                        "subtitle" => "Uptime is: " . $uptimetime1
                    )
                )
            )
        )
    );
} else {
   array(
       "icon" => "error",
       "type" => "label",
        "title" => $name1,
        "subtitle" => "Down since: " . $lastseendate1);
}

try {
    echo "<p>Publish</p>";
    $publishResponse = request(options, $publishRequest);
    echo "<p>".$publishResponse."</p></br></br>";
}
7
  • what is options? Commented May 2, 2019 at 12:36
  • What does $status1 contain before the IF? Commented May 2, 2019 at 12:36
  • 6
    You have syntax errors. Could please fix them first? Commented May 2, 2019 at 12:36
  • 2
    You need to set the array in the ELSE to $publishRequest too. Commented May 2, 2019 at 12:37
  • 3
    $publishRequest = array() without semicolon is a syntax error Commented May 2, 2019 at 12:40

1 Answer 1

2

If $status1 is not == 'up' then you create an array in the ELSE but dont set it into the variable $publishRequest

else {
   $publishRequest = array(
                        "icon" => "error",
                        "type" => "label",
                        "title" => $name1,
                        "subtitle" => "Down since: " . $lastseendate1);
}
Sign up to request clarification or add additional context in comments.

3 Comments

no, $publishRequest already defined before the if-else block
Well the array in ELSE is useless without it being assigned to something.
Weird, if you had $publishRequest defined before the IF it shouldn't be undefined.

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.