11-30-2009, 03:20 PM
|
#10 (permalink)
|
|
The Prestige
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
|
Quote:
Originally Posted by ETbyrne
PHP Code:
class myClass
{
public function myFunction()
{
$arguments = func_get_args();
}
}
You can then use any number of arguments on that function.
PHP Code:
$obj = new myClass();
$obj->myFunction();
$obj->myFunction(1,'two');
$obj->myFunction(3,4,5,'six');
|
Quote:
Originally Posted by adamdecaf
You can always do this.
PHP Code:
function my_funct($parm1 = '', $parm2 = '') {
}
Where the default value is assigned to the argument and overwritten by the function call.
PHP Code:
function my_funct($first = 'John', $last = 'Doe') {
echo $first . ' ' . $last;
}
// Just a note, the optional arguments are best
// added last in the order, otherwise you will
// start to get syntax/logic errors.
// Adam Doe
my_funct('Adam');
|
True, the calling of the method would become like I want it.
Although the second example would not be exactely like I want it since I still would have to define how many arguments it would need.
However, the calling of the method is not the only thing. It's how things are handled within the method. If using your example:
PHP Code:
$obj->myMethod(1);
$obj->myMethod(1, "String");
This would still be in the same method and the method would become quite large depending on what the method does.
__________________
|
|
|
|