Coding Style: passing values to functions
Posted: Thu Jun 12, 2003 5:50 am
Personally, I prefer doing the whole passing values to functions-business with associative arrays - but I am wondering about the pros and cons - as I haven't had to do any mission-critical stuff and write very performance-oriented code.
How do you do it (pass values to functions that is
) ?
1. Do you use the rather linear
myFunction($value1, $value2, $value3, $value4, etc.)
2. or do you do it in OOP exclusively and set the properties before the function call?
$myClass->property1="bla1";
$myClass->property2=bla2;
$myClass->property2="bla3";
$myClass->myFunction();
3. or do you do it with arrays
$myArray=array("myValue1"=>"value1","myValue2"=>"value2");
To me the greatest benefits in using associative arrays is that
a) very easy to pass values from a form-submit to a function
b) it's a rather clean method imho as it keeps the code clean and makes debugging easy (better than 1.) and it doesn't bloat the code unnecessarily (better than 2.)
c) many more options in terms of data-accessability than OOP (see array-functions) - e.g. if necessary "array to oop" conversion is done with two lines of code, but "oop to array" - yikes.
Whatcha think?
How do you do it (pass values to functions that is
1. Do you use the rather linear
myFunction($value1, $value2, $value3, $value4, etc.)
2. or do you do it in OOP exclusively and set the properties before the function call?
$myClass->property1="bla1";
$myClass->property2=bla2;
$myClass->property2="bla3";
$myClass->myFunction();
3. or do you do it with arrays
$myArray=array("myValue1"=>"value1","myValue2"=>"value2");
To me the greatest benefits in using associative arrays is that
a) very easy to pass values from a form-submit to a function
b) it's a rather clean method imho as it keeps the code clean and makes debugging easy (better than 1.) and it doesn't bloat the code unnecessarily (better than 2.)
c) many more options in terms of data-accessability than OOP (see array-functions) - e.g. if necessary "array to oop" conversion is done with two lines of code, but "oop to array" - yikes.
Whatcha think?