FUDforum
Fast Uncompromising Discussions. FUDforum will get your users talking.

Home » Imported messages » comp.lang.php » Sending nothing when function expects variable
Show: Today's Messages :: Polls :: Message Navigator
Return to the default flat view Create a new topic Submit Reply
Re: Sending nothing when function expects variable [message #178963 is a reply to message #178961] Tue, 28 August 2012 07:21 Go to previous messageGo to previous message
Anders Wegge Keller is currently offline  Anders Wegge Keller
Messages: 30
Registered: May 2012
Karma:
Member
Jason C <jwcarlton(at)gmail(dot)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.*
[Message index]
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: How can i know the propery of a javascript object how can i see what object inclue
Next Topic: Folder Permissions
Goto Forum:
  

-=] Back to Top [=-
[ Syndicate this forum (XML) ] [ RSS ]

Current Time: Sun Nov 10 13:09:01 GMT 2024

Total time taken to generate the page: 0.04538 seconds