CodeIgniter Forums
How do these arguments work? [, int $status_code= 500 ] ? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: How do these arguments work? [, int $status_code= 500 ] ? (/showthread.php?tid=1441)



How do these arguments work? [, int $status_code= 500 ] ? - lexxtoronto - 03-10-2015

Im not too clear how exactly these arguments are passed.

show_error('message' [, int $status_code= 500 ] )

Why isnt comma just after 'message'? And why square brackets?


Oh and this one too show_404('page' [, 'log_error']) ---- first example it is an int $status_code and here its just 'log_error' -what is the difference?

PS. I do apologize for my stupid questions.


RE: How do these arguments work? [, int $status_code= 500 ] ? - frocco - 03-10-2015

[] are just a replacement for array()

The comma is need because you are passing an array.

The show_404 will display the 404 error message to the browser (not found). The second parameter log_error is a value of TRUE or FALSE.
TRUE will log the error message if logging is enabled.


RE: How do these arguments work? [, int $status_code= 500 ] ? - lexxtoronto - 03-10-2015

Thank you, that's what I thought. Is this regular PHP or CI? If its PHP I will try to find more online to read about it.


RE: How do these arguments work? [, int $status_code= 500 ] ? - Narf - 03-11-2015

[] here has nothing to do with arrays ... square brackets are a de-facto standard notation for marking optional parameters in documentation.


RE: How do these arguments work? [, int $status_code= 500 ] ? - lexxtoronto - 03-18-2015

Im going to trust Narf since he has three stars lol, but seriously I will have to look into that deeper since Im confused now. Thank you all


RE: How do these arguments work? [, int $status_code= 500 ] ? - CroNiX - 03-18-2015

Narf is correct. In docs, [] as a parameter denote an optional parameter (also why the comma is inside the [] because if you use the optional parameter, you need the comma to separate parameters).

This is how the official PHP docs (and most others) are written. Example: http://php.net/manual/en/function.html-entity-decode.php