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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T17:16:43+00:00 2026-06-12T17:16:43+00:00

I have a unique situation that is hard to debug. I need to set

  • 0

I have a unique situation that is hard to debug.

I need to set a global string inside a php class that is not strictly defined as a global, the class must be in another file.

The file.php with the string has simply this:

//this cannot be changed
$foo_version = '1.1.1';

The example.php file trying to access this string must use a class:

class Bar extends Task {

      public function main() {

           require_once('../file.php');
           //global $foo_version; this doesn't work
           // update the database with this string, does not work

           update_option( 'db_field', $foo_version );

          }
      }

How can I get the $foo_version to return something inside the class?

Also nothing can be defined/done outside the class.

  • 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-12T17:16:45+00:00Added an answer on June 12, 2026 at 5:16 pm

    What you have is a variable $foo_version and it can easily be changed. You can use define to make it a constant instead see PHP DOC

    define("FOO_VERSION", "1.1.1");
    
    class Bar extends Task {
        public function main() {
            require_once ('../file.php');
            update_option('db_field', FOO_VERSION);
        }
    }
    

    If you insist Replace require_once with require your code would work because PHP will check if the file has already been included, and if so, not include (require) it again.

    If you have used this in another class definitely it would not work. Change your code to the following

    class Bar extends Task {
        public function main() {
            require ('../file.php');
            update_option('db_field', $foo_version);
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an interesting situation, well it's probably not that unique at all, but
I have a situation where I need to store a globally unique identifier that
I have a unique situation where I'm building a site that will call data
Greetings! Situation: We have a CRM system that generates unique customer IDs. Now we
I have an SQL database with a set of tables that have Unique Id's.
I have a situation where I need to add an arbitrary unique id to
Please read the entire question. I have a unique situation with several constraints that
I have a unique situation where I am building a DDD based system that
I have a somewhat unique situation that I can't quite get working. I've followed
I have a weird situation happening that I'm not quite understanding. I have a

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.