0

I have 2 variables $b and $c defined in an if() function, but when running the function, I keep getting an Undefined variable $b.

public function printPDF()
    {
        /*Treadwear*/
        if ($this->tread_wear == 140) {
            $c = 140;
        } elseif ($this->tread_wear == 0) {
            $b = 120;
        } elseif ($this->tread_wear < 50) {
            $b = 80;
        } elseif ($this->tread_wear < 140) {
            $b = 40;
        } elseif ($this->tread_wear < 201) {
            $b = 20;
        }

        $pdf = new Pdf('/docs/ax_reg_form.pdf');
        $result = $pdf->fillForm([
            ...
            'b' => $b,
            'c' => $c,
            ...
        ])
            ->needAppearances()
            ->saveAs('docs/reg-forms/'.$this->usercar->user->id.'_'.strtolower($this->usercar->user->first_name).'_'.strtolower($this->usercar->user->last_name).'_'.'car_class.pdf');

        // Always check for errors
        /*if ($result === false) {
            $error = $pdf->getError();
        }*/

        session()->flash('url', '/docs/reg-forms/'.$this->usercar->user->id.'_'.strtolower($this->usercar->user->first_name).'_'.strtolower($this->usercar->user->last_name).'_'.'car_class.pdf');

        return redirect()->route('usercar.show', $this->usercar->id);

    }
2
  • 3
    Your declarations of $b and $c are inside if and elseif so only one of them will be declared. Maybe you forget about else statement? Commented Apr 10, 2022 at 19:23
  • That was it. Can't believe I missed that. Put in an answer so I can accept it. Thanks. Commented Apr 10, 2022 at 19:30

1 Answer 1

1

Your declarations of $b and $c are inside if and elseif so only one of them will be declared. Maybe you forget about else statement?

Sign up to request clarification or add additional context in comments.

Comments

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.