• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
warning "missing argument"


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

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

calling that function from a controller like....


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?


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

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

but im not sure if it is that Wink

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?

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

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!

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

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

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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.