Re: [PHP] Function arguments
Most of my program functions use the first approach I have what ever must be given because the nature of the functions only exists because it does certain things. I then have the last argurment passed be an array. This will contain all the data that I might want to use inside the function other then the required fields. for example I have a 'BOXTOP()' and 'BOXBOTTOM()' function set. for the 'BOXTOP()' function I require the first argument but after that is an array. with this, I can customize the with of my box and if it isn't given it defaults to a predefined with. I can do the same thing with themes, colors, borders, cellpadding, cellspacing, etc... Then it will pass this same information to the corresponding 'BOXBOTTOM()' function. This keeps things very nice and clean. inside the 'BOXTOP()' function is a mess, but once it is how you want it, you will find that it is very easy to work with functions formated like this. Jim Lucas - Original Message - From: "Hardik Doshi" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Friday, August 15, 2003 8:53 AM Subject: [PHP] Function arguments > Hi Group, > > I have a question on overloaded function. > > What is the best way to pass the arguments so it is > easy to maintain in future if function behaviour > changes by adding/removing one or more arguments? > > Currently i am passing arguments in array. But i think > it is not the clean way to do it and another approach > i am using is functionName(arg1, arg2='', arg3='') but > here again i think it is not easy to maintain. > > Please let me know if you guys have other options or > improved version of above options. > > Thanks > > Hardik > > __ > Do you Yahoo!? > Yahoo! SiteBuilder - Free, easy-to-use web site design software > http://sitebuilder.yahoo.com > > -- > PHP General Mailing List (http://www.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function arguments
>What is the best way to pass the arguments so it is easy to maintain in >future if function behaviour changes by adding/removing one or more >arguments? > >Currently i am passing arguments in array. But i think it is not the >clean way to do it and another approach i am using is functionName(arg1, >arg2='', arg3='') but here again i think it is not easy to maintain. According to http://php.net/manual/en/functions.arguments.php, Variable-length argument lists PHP 4 has support for variable-length argument lists in user-defined functions. This is really quite easy, using the func_num_args(), func_get_arg(), and func_get_args() functions. No special syntax is required, and argument lists may still be explicitly provided with function definitions and will behave as normal. - michal migurski- contact info and pgp key: sf/cahttp://mike.teczno.com/contact.html -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] Function arguments
Hello, If you are worried about this issue your best option is to switch to an object oriented approach. all the best Hardik Doshi wrote: Hi Group, I have a question on overloaded function. What is the best way to pass the arguments so it is easy to maintain in future if function behaviour changes by adding/removing one or more arguments? Currently i am passing arguments in array. But i think it is not the clean way to do it and another approach i am using is functionName(arg1, arg2='', arg3='') but here again i think it is not easy to maintain. Please let me know if you guys have other options or improved version of above options. Thanks Hardik __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- Raditha Dissanayake - http://www.radinks.com/sftp/ Lean and mean Secure FTP applet with Graphical User Inteface. just 150 Kilo Bytes -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Function arguments
Hi Group, I have a question on overloaded function. What is the best way to pass the arguments so it is easy to maintain in future if function behaviour changes by adding/removing one or more arguments? Currently i am passing arguments in array. But i think it is not the clean way to do it and another approach i am using is functionName(arg1, arg2='', arg3='') but here again i think it is not easy to maintain. Please let me know if you guys have other options or improved version of above options. Thanks Hardik __ Do you Yahoo!? Yahoo! SiteBuilder - Free, easy-to-use web site design software http://sitebuilder.yahoo.com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP] function arguments
expanding on this... function func($arga, $argb, $argc='') { do_something_with_arga($arga); do_another_thing_with_argb($argb); if ($argc != '') do_somthing_with_argc($argc); } on 1/18/02 1:19 PM, Ben Sinclair at [EMAIL PROTECTED] wrote: > You can do something like this: > > function myFunction($a = "hello", $b = "world") { } > > Both arguments are optional and have default values. This is in the > documentation. > > -- > Ben Sinclair > [EMAIL PROTECTED] > - Original Message - > From: "Malte Fucks" <[EMAIL PROTECTED]> > To: <[EMAIL PROTECTED]> > Sent: Thursday, January 18, 2001 2:17 PM > Subject: [PHP] function arguments > > > Hi, how do i tell a function which arguments can be passed and which must be > passed... > > example: > function func($arga, $argb, $argc) > { > do_something_with_arga; > do_another_thing_with_argb; > and_if_argc_was_passed_do_something_with_it_too; > } > > because i dont want to pass argc if i dont need it, and to pass void arguments > like '' is annoying... > > -- mike cullerton michaelc at cullerton dot com -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP] function arguments
You can do something like this: function myFunction($a = "hello", $b = "world") { } Both arguments are optional and have default values. This is in the documentation. -- Ben Sinclair [EMAIL PROTECTED] - Original Message - From: "Malte Fucks" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Thursday, January 18, 2001 2:17 PM Subject: [PHP] function arguments Hi, how do i tell a function which arguments can be passed and which must be passed... example: function func($arga, $argb, $argc) { do_something_with_arga; do_another_thing_with_argb; and_if_argc_was_passed_do_something_with_it_too; } because i dont want to pass argc if i dont need it, and to pass void arguments like '' is annoying... -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] function arguments
Hi, how do i tell a function which arguments can be passed and which must be passed... example: function func($arga, $argb, $argc) { do_something_with_arga; do_another_thing_with_argb; and_if_argc_was_passed_do_something_with_it_too; } because i dont want to pass argc if i dont need it, and to pass void arguments like '' is annoying...