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

  • Home
  • SEARCH
  • 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 4568170
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T19:02:17+00:00 2026-05-21T19:02:17+00:00

By default a PHP function uses $_GET variables. Sometimes this function should be called

  • 0

By default a PHP function uses $_GET variables. Sometimes this function should be called in an situation where $_GET is not set. In this case I will define the needed variables as parameter like: actionOne(234)

To get an abstract code I tried something like this:

function actionOne($id=$_GET["ID"])

which results in an error:

Parse error: syntax error, unexpected T_VARIABLE

Is it impossible to define an default parameter by using an variable?

Edit

The actionOne is called “directly” from an URL using the framework Yii. By handling the $_GET variables outside this function, I had to do this on an central component (even it is a simple, insignificant function) or I have to change the framework, what I don’t like to do.

An other way to do this could be an dummy function (something like an pre-function), which is called by the URL. This “dummy” function handles the variable-issue and calls the actionOne($id).

  • 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-05-21T19:02:18+00:00Added an answer on May 21, 2026 at 7:02 pm

    No, this isn’t possible, as stated on the Function arguments manual page:

    The default value must be a constant
    expression, not (for example) a
    variable, a class member or a function
    call.

    Instead you could either simply pass in null as the default and update this within your function…

    function actionOne($id=null) {
        $id = isset($id) ? $id : $_GET['ID'];
        ....
    }
    

    …or (better still), simply provide $_GET[‘ID’] as the argument value when you don’t have a specific ID to pass in. (i.e.: Handle this outside the function.)

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This does not work with my PHP 5.3.3 installation on WAMP / Windows 7:
Possible Duplicate: Override default php function Is there a way to detect that a
For PHP, what is the default time after which an HTTP request is deemed
I am doing the following in PHP: exec('java -jar /opt/flex3/lib/mxmlc.jar +flexlib /opt/flex3/frameworks MyAS3App.as -default-size
I'm trying to make a simple site that uses php and the Twitter API
Columbus, Ohio is in EDT timezone but PHP::DateTime uses these php timezones and I
I've got a jQuery function that retrieves a JSON response from a PHP page.
I have a function which returns object array like that: <?php function sth() {
I am developing a MVC application with PHP that uses XML and XSLT to
So made an api, that uses variables in an url to load an image.

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.