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 #178967 is a reply to message #178962] Tue, 28 August 2012 13:01 Go to previous messageGo to previous message
Scott Johnson is currently offline  Scott Johnson
Messages: 196
Registered: January 2012
Karma:
Senior Member
On 8/28/2012 12:08 AM, Goran wrote:
> On 28.8.2012 8:51, Jason C wrote:
>> or is there a way to set PHP to ignore this warning by default?
>
> Declare function this way:
>
> function whatever($a, $b = '', $c = '')
> {
> // your existing code
> }
>

This is a common problem, at least for me when first creating custom
class libraries for repeated use.

I find a way to make a function more useable over several needs and I
add extra parameters.

The default argument method works OK but you also need to make sure that
the defaults are received in order.

For example.

if you write
function func($a, $b='', $c='')

You cannot call $c without $b.

func('a','c')
will put 'c' in $b.

A few options that I have used is to pass an array of needed variables.

function func($arg_ary) {
//parse out $arg_ary
}
Call
$args = array('a'=>'a data','c'=>'c data')
func($args)


Or use the php built function

function func() {
// put incoming args in an array
$args_ary = func_get_args();

// Parse $args_ary
}

call
func('a','b');


These are obvious bare bone non-working examples with no error checking.

Also
http://www.php.net/manual/en/index.php is your best friend.
[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 11:28:44 GMT 2024

Total time taken to generate the page: 0.04025 seconds