CodeIgniter Forums

Full Version: warning "missing argument"
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[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

El Forum

[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

El Forum

[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?

El Forum

[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!

El Forum

[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

El Forum

[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.

El Forum

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