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 8941475
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T11:18:39+00:00 2026-06-15T11:18:39+00:00

On the php.net manual page for define() , there’s a user-contributed note that suggests

  • 0

On the php.net manual page for define(), there’s a user-contributed note that suggests that you can usefully call define() from within a function.

Lightly paraphrasing, the suggestion is to create a function like this:

<?php  
function xdefine($a) {
  foreach($a as $k => $v)
    define($k, $v); 
}  
?>

and then to subsequently use it like this:

<?php
xdefine(array(
    "SECOND" => 1,
    "MINUTE" => 60,
    "HOUR" => 3600,
    "DAY" => 86400,
    "WEEK" => 604800,
    "MONTH" => 2592000, // 30 days month
    "YEAR" => 31536000,
    "LEAPYEAR" => 31622400
));
?>

But both my sense and my experience are that this doesn’t work: after the xdefine() call, each of the identifiers just evaluates to its own name, not to the value that xdefine() supposedly bound to it.

The reason seems pretty obvious to me (i.e., because the symbols get their values as the module containing the call to xdefine() is being parsed/loaded), but maybe there’s some subtlety I’m missing. The author of the post named his function something different, using a cute Unicode character, but I’m pretty sure that’s just a cosmetic difference.

(BTW, something similar does work for me if I don’t define a function like xdefine(), but rather, just run the same foreach() loop over the contents of the array, provided that both the loop and the array are at module scope. This is also expected behavior, from my perspective.)

So, can someone look at the original post and tell me if there’s really anything to it? Or does the author just have it wrong?

(I’d post this to the referenced php.net page, but I think I will get more eyes on the question faster if I post it here instead 🙂

  • 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-15T11:18:40+00:00Added an answer on June 15, 2026 at 11:18 am

    The sample function works. The scope of a constant is global. However, the reason(s) to do this are dubious imho.

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

Sidebar

Related Questions

http://php.net/manual/en/function.trim.php The manual entry does say that I can remove any specified leading or
The most recent comment on PHP's in_array() help page ( http://uk.php.net/manual/en/function.in-array.php#106319 ) states that
http://php.net/manual/en/pdo.prepared-statements.php If an application exclusively uses prepared statements, the developer can be sure that
The php.net page here http://www.php.net/manual/en/mysqlinfo.library.choosing.php says this Configure commands for using mysqlnd // Recommended,
I have gone through this page... http://www.php.net/manual/en/function.hash.php MD5 is 32 characters long while sha1
I saw this example in php manual page http://www.php.net/manual/en/session.examples.php The example will create a
The PHP page of Soap Server (I've seen it): http://www.php.net/manual/en/soapserver.soapserver.php But I'm missing an
I'm just about ready to cry. I have read the php.net manual page, tried
http://php.net/manual/en/function.mysql-escape-string.php Why is that?
I'am a big fan of http://php.net/manual/en/function.flush.php Can I do the same thing using Java?

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.