leefentress Posted September 5, 2008 Share Posted September 5, 2008 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; } } } Quote Link to comment https://forums.phpfreaks.com/topic/122905-warning-missing-argument-3-when-i-only-need-to-pass-2-parameters/ Share on other sites More sharing options...
Ken2k7 Posted September 5, 2008 Share Posted September 5, 2008 Please post the relevant code. Which code sent off the error? Also, the CodeGen() function currently doesn't take any parameters. If it's supposed to be unlimited, then you didn't code it the right way. Quote Link to comment https://forums.phpfreaks.com/topic/122905-warning-missing-argument-3-when-i-only-need-to-pass-2-parameters/#findComment-634808 Share on other sites More sharing options...
leefentress Posted September 8, 2008 Author Share Posted September 8, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/122905-warning-missing-argument-3-when-i-only-need-to-pass-2-parameters/#findComment-636214 Share on other sites More sharing options...
sasa Posted September 8, 2008 Share Posted September 8, 2008 function AddCart($cd, $frompage, $off='deafult value') Quote Link to comment https://forums.phpfreaks.com/topic/122905-warning-missing-argument-3-when-i-only-need-to-pass-2-parameters/#findComment-636286 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.