Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.php > #6892
| Newsgroups | comp.lang.php |
|---|---|
| Subject | Re: Sending nothing when function expects variable |
| References | <03b15810-f401-4ad2-a1a4-c4f10f0f311e@googlegroups.com> |
| From | Anders Wegge Keller <wegge@wegge.dk> |
| Date | 2012-08-28 09:21 +0200 |
| Message-ID | <87wr0jjxc5.fsf@huddi.jernurt.dk> (permalink) |
| Organization | SunSITE.dk - Supporting Open source |
Jason C <jwcarlton@gmail.com> writes:
> But then in the error log, I get these warnings:
>
> PHP Warning: Missing argument 2 for q()...
> PHP Warning: Missing argument 3 for q()...
> Does this mean that I need to go back through all of the scripts
> (dozens of them) and change all of the whatever() references to:
> whatever('this thing', false, false);
Not neccesarily. You can declare the function with default arguments:
function whatever($a, $b = "something", $c = "something else") {
...
}
If no arguments for b and c is passed, the function will get the
defaults instead. This replacement will not be visible inside the
function. If this is of importance, or the defaults are calculated
somehow, you'd be better off using NULL as default value:
function whatever($a, $b = NULL, $c = NULL) {
if (!isset($b)) {
/* Calculate default */
$b = <<some complex operation>>;
}
}
Example 3 and 4 in the manual page describe your case pretty well:
<http://php.net/manual/en/functions.arguments.php>
> or is there a way to set PHP to ignore this warning by default?
In theory you could use error_reporting(E_ERROR), but that would be
purely cosmetic.
--
/Wegge
Leder efter redundant peering af dk.*,linux.debian.*
Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Sending nothing when function expects variable Jason C <jwcarlton@gmail.com> - 2012-08-27 23:51 -0700
Re: Sending nothing when function expects variable Goran <goran@nospam.com> - 2012-08-28 09:08 +0200
Re: Sending nothing when function expects variable Scott Johnson <noonehome@chalupasworld.com> - 2012-08-28 06:01 -0700
Re: Sending nothing when function expects variable Anders Wegge Keller <wegge@wegge.dk> - 2012-08-28 09:21 +0200
Re: Sending nothing when function expects variable "Álvaro G. Vicario" <alvaro.NOSPAMTHANX@demogracia.com.invalid> - 2012-08-28 09:55 +0200
Re: Sending nothing when function expects variable Tim Streater <timstreater@greenbee.net> - 2012-08-28 09:23 +0100
csiph-web