Jump to content

RESOLVED: Function Warning: Missing Argument

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
6 replies to this topic

#1
Takumi

Takumi

    Newbie

  • Members
  • PipPip
  • 16 posts
I have made a function which can contain a value, but it is not required. When the $showerror is set he must show the error immediatly. But when I enter showerror() he shows an warning. How can I remove this warning?

Function:
function showerror($showerror) {

	// showerror() om de globale error op te halen, anders showerror($error);

	if (isset($showerror)) {

		echo "<div class='error'>$showerror</div>";

	} else {

		global $customerror;

		if (isset($customerror) and !empty($customerror)) {

			foreach ($customerror as $page => $error) {

				if ($page == $_GET['a']) {

					echo "<div class='error'>$error</div>";

					return true;

				}

			}

		}

	}

	return false;

}

Best Regards,
Takumi

Edited by Takumi, 30 October 2010 - 12:51 PM.


#2
Calgon

Calgon

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts

function showerror($showerror = "") {

    // showerror() om de globale error op te halen, anders showerror($error);

    if ($showerror == "") {

        echo "<div class='error'>$showerror</div>";

    } else {

        global $customerror;

        if (isset($customerror) and !empty($customerror)) {

            foreach ($customerror as $page => $error) {

                if ($page == $_GET['a']) {

                    echo "<div class='error'>$error</div>";

                    return true;

                }

            }

        }

        return false;

    }  

}

Try this. (edited).

See, I was right all along...

Edited by Calgon, 31 October 2010 - 01:31 AM.


#3
Takumi

Takumi

    Newbie

  • Members
  • PipPip
  • 16 posts
Thanks for your fast reply, but this isn't working.

Takumi

#4
Calgon

Calgon

    Learning Programmer

  • Members
  • PipPipPip
  • 56 posts
Try now, I've updated the code in my previous post. Need to get used to PHP again, used to using another language. The code isn't as efficient as possible, sorry.

#5
Takumi

Takumi

    Newbie

  • Members
  • PipPip
  • 16 posts
This will set $showerror to "", so the error you have entered will be removed. This isn't working either.

Takumi

#6
Alexander

Alexander

    It's Science!

  • Moderators
  • 4,124 posts
Hello Takumi, you must set it as a default but check for it being empty as well, it would look something such as this:
function showerror($showerror = '') {
    // showerror() om de globale error op te halen, anders showerror($error);
    if ($showerror != '') {
        echo "<div class='error'>$showerror</div>";
    } else {
        global $customerror;
        if (isset($customerror) and !empty($customerror)) {
            foreach ($customerror as $page => $error) {
                if ($page == $_GET['a']) {
                    echo "<div class='error'>$error</div>";
                    return true;
                }
            }
        }
    }
    return false;
}  
I had not looked too much into the logic of your script, but both showerror() and showerror('foo') should work provided you had written the function correctly.
Be sure to read the updated FAQ! || Health is achieved through the same 10,000 steps.
If a suggested code/method fails, informing us is less important than telling us why or what errors occurred.

#7
Takumi

Takumi

    Newbie

  • Members
  • PipPip
  • 16 posts
Thanks I can see what I was doing wrong, thanks everyone!

Takumi