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
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.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.