Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.php > #6895

Re: Sending nothing when function expects variable

From Scott Johnson <noonehome@chalupasworld.com>
Newsgroups comp.lang.php
Subject Re: Sending nothing when function expects variable
Date 2012-08-28 06:01 -0700
Organization A noiseless patient Spider
Message-ID <k1ifef$v68$1@dont-email.me> (permalink)
References <03b15810-f401-4ad2-a1a4-c4f10f0f311e@googlegroups.com> <k1hqq4$krc$1@news.metronet.hr>

Show all headers | View raw


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.



Back to comp.lang.php | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


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