CodeIgniter Forums
warning "missing argument" - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: warning "missing argument" (/showthread.php?tid=1711)



warning "missing argument" - El Forum - 06-21-2007

[eluser]Unknown[/eluser]
hi,

i have a model with a function which has some arguments with default values like...

Code:
function doSomething($arg1, $arg2="foo") { ... }

calling that function from a controller like....

Code:
doSomething("stupid");

returns a warning message saying
Quote:Missing argument 2 for Foo_model::doSomething(), called in /path/to/file.php on line XX and defined

what i'm doing wrong?

thanks
martin


warning "missing argument" - El Forum - 06-21-2007

[eluser]Robert M.[/eluser]
i think i have seen something like that before. I might it was that the order is important.

try
Code:
function doSomething($arg2="foo",arg1){...}

but im not sure if it is that Wink


warning "missing argument" - El Forum - 06-21-2007

[eluser]pr0digy[/eluser]
If you are calling the correct function there should not be an error. Could it be that you're calling a function with the same name, but different parameters in a different/parent model?


warning "missing argument" - El Forum - 06-21-2007

[eluser]Phil Sturgeon[/eluser]
By default whenever you create a function ALWAYS set the arguments a default value.

Code:
function doSomething($arg1 = NULL, $arg2="foo") { ... }

It can be = '', = 0, = FALSE, whatever. PHP does not require type casting like many other languages but it is not only good practise to do so whenever possible, but shuts up the CI warning messages ^_^

CI seems to be stricter than PHP which I like, it makes my code better!


warning "missing argument" - El Forum - 06-22-2007

[eluser]Unknown[/eluser]
thank you all for your replies...

my fault was that i was using not the latest version of the model file from the repository... damn... Wink


warning "missing argument" - El Forum - 06-22-2007

[eluser]Flayra[/eluser]
[quote author="thepyromaniac" date="1182485324"]CI seems to be stricter than PHP which I like, it makes my code better![/quote]
Actually, CI just sets the error output higher than what PHP is by default. It means that warnings like outputting a variable not set, missing arguments, et. are shown.

These errors still occur when using PHP without CI, they're simply not shown.


warning "missing argument" - El Forum - 06-22-2007

[eluser]Phil Sturgeon[/eluser]
Ahh now I know! I will be enabling warning messages during development of non-CI stuffs, I like it ^_^