Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8067043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T12:09:59+00:00 2026-06-05T12:09:59+00:00

In php we can pass default arguments to a function like so function func_name(arg1,arg2=4,etc…)

  • 0

In php we can pass default arguments to a function like so

function func_name(arg1,arg2=4,etc...) {

but to my understanding we can not pass a function call so this is illegal:

function func2_name(arg1,arg2=time(),etc...) {

so when I want to do a function value (imagine like the time function the value cant be known ahead of runtime) I have to do a kind of messy work around like so:

function func3_name(arg1,arg2=null,etc...) {
    if(arg2==null) arg2 = time();

I was wondering if anyone knows a better way, a cleaner way to pass in function call values as default arguments in php? Thanks.

Also is there any fundamental reason in php language design that it doesn’t allow function calls as default arguments (like does it do something special in the preprocessing?) or could this become a feature in future versions?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-05T12:10:00+00:00Added an answer on June 5, 2026 at 12:10 pm

    Well, the short answer is that there is no better way to do it, to my knowledge. You can, however, make it look somewhat neater by using ternary operators.

    function func3_name(arg1,arg2=null,etc...) {
      arg2 = (arg2==null ? time() : arg2);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In php 5.3, when you create an anonymous function, can you set the default
I've written a PHP function that can accept 10 parameters, but only 2 are
In php there is a list of all the parameters you can pass to
function newPage(pagenum) { /* load page default from server - pass product name */
My controller action requires a parameter, but I can't get KO3's router to pass
I have the following PHP function: function func_name($name = 'John', $country = 'USA') {
In manual there is create_function function and you can pass result from that function
Using for loop in PHP can we have numbers associate with a variable name?
how to make php can read log file in /var/log/.... I tried this code
I was wondering if PHP can do this as there seems to be no

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.