Jump to content

Warning: Missing argument 3 when I only need to pass 2 parameters


Recommended Posts

I've got this class where I only need to use the third argument when instantiating it if I want to basically turn off this one function in it, CodeGen. So I don't need to pass a parameter there if I just want to leave it on. But I get a warning from PHP telling me its missing argument 3. I'm guessing there's a better way all around to set this up anyway. I've got a bunch of pages set up with tables that have this one column where down that columns cells I've got a call to the CodeGen function in each of them. The function just takes the arguments from the first 2 parameters from when the object is instantiated and echoes out some html that varies according to those parameters. I've already got this code on a bunch of pages, but I need to turn the function off on some of them with the option of turning it back on later because I don't need the Add to Cart buttons it makes on all the pages right now but might need them later.

 

class AddCart {
var $track = 1;
var $cd;
var $frompage;
var $apath = "/Albums/";
var $off = "on";

function AddCart($cd, $frompage, $off) {
	$this->cd = $cd;
	$this->frompage = $frompage;
	$this->off = $off;
}

function CodeGen() {
	$track = $this->track;
	$code =
	"
	<form method='post' action='../../cart.php' class='NoMarginNoPadding'>
	<input type='submit' name='submit' value='Add to Cart' />
	<input type='hidden' name='id' value='MP3-" . $this->ZeroFill($track) . "-" . $this->cd . "'>
	<input type='hidden' name='mode' value='add'>
	<input type='hidden' name='frompage' value='" . $this->apath . $this->frompage . "/index.php' />
	</form>
	";

	if ($this->off != "off") {
	echo $code;
	$this->track++;
	}
}

function ZeroFill($track) {
	if ($track < 10) {
		$newtrack = 0 . $track;
		return $newtrack;
	}
	else {
	return $track;
	}
}
}

Nevermind the code. I just need to know one thing really. If you have a function that takes up to 3 parameters but sometimes you don't need to pass the third one because it is optional, how do you make it so the warning error saying the function is missing an argument doesn't display?

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.