Jump to content

"Flexible" functions a possibility?


The Bat

Recommended Posts

Hello,

 

Is it at all possible in PHP to have "flexible" functions? For example, there's a function which has 3 parameters, and I only want to utilize 2 - the first one and last one. Instead of typing

 

myFunc('first', false, 'third');

 

Could I/how would I do this?

 

myFunc('first', $thirdparam = 'third');

 

(Assuming $thirdparam is the same variable used to declare the third parameter when creating the function.)

 

Using Rails has had me wanting this functionality in PHP ;) Thanks for the help!

Link to comment
https://forums.phpfreaks.com/topic/64217-flexible-functions-a-possibility/
Share on other sites

The ampersands demonstrate how to use references when passing arguments as arrays.  If you don't use references, you don't need to worry about them :)  Just use the "bob" line for all your variables.

 

If you do want references, the "bill" line in the example demonstrates that you must take a reference in two places for it to be effective.  If you remove either one, then you will not get a reference back to the original variable.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.