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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T13:06:09+00:00 2026-05-11T13:06:09+00:00

Current situation: I have the current version of my MVC Framework which uses classes

  • 0

Current situation:

  • I have the current version of my MVC Framework which uses classes as controllers.
  • I have some ‘vintage’ modules from my old MVC Framework which uses simple, flat includes as controllers.

Much simplified that means:

New Version:

<?PHP class blaController extends baseController {     private $intVar;      function dosomethingFunction() {         $this->intVar = 123;         $this->view('myView');     } } ?> 

Old Version:

<?PHP $globalVar = 123; // view 'controllername' is automatically shown ?> 

I’m now trying to write a wrapper to be able to use my old controllers in my new MVC without having to rewrite everything. To do so, I have a ‘wrapper’ controller:

class wrapController extends baseController {     function dosomethingFunction() {         require 'old_dosomething.function.php';         $this->view('old_dosomething_view');     } } 

(Once again: This is VERY, VERY simplified – just to get the idea over. Not actual code.)

The problem with that approach is, that the previously global variable $globalVar now only exists inside of the method ‘dosomethingFunction’ and cannot be accessed by the view.

This wouldn’t be the case if I could force the require to behave as ‘in global scope’ so that $globalVar would once again be available in global scope.

So: Is there some way to achieve ‘require_global‘ or something similar?

(One solution for my problem would be to modify my old controllers to start with a bunch of ‘global’ commands, but I’d prefer a solution where I don’t have to change so much of that old code.)

(Note: Please don’t tell me that GLOBALS are bad. It totally misses the point of this question. Just accept that it is a requirement to keep some old code working in a newer, cleaner environment.)

  • 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. 2026-05-11T13:06:10+00:00Added an answer on May 11, 2026 at 1:06 pm

    You can add local variables defined within dosomethingFunction() to global scope:

    class wrapController extends baseController {     function dosomethingFunction() {         require 'old_dosomething.function.php';         //begin added code           $vararr = get_defined_vars();         foreach($vararr as $varName => $varValue)                $GLOBALS[$varName] = $varValue;                     //end added code                   $this->view('old_dosomething_view');     } } 

    Note, that for this to work as expected, you should call require before using any other thing in the function. get_defined_vars() returns only variables from the current scope, so no array_diff hacks are needed.

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

Sidebar

Ask A Question

Stats

  • Questions 88k
  • Answers 88k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Use FtpWebRequest, with a method of WebRequestMethods.Ftp.MakeDirectory. For example: using… May 11, 2026 at 5:47 pm
  • Editorial Team
    Editorial Team added an answer if (preg_match('/^[0-9]+(?:\.[0-9]+)?$/', $subject)) { # Successful match } else {… May 11, 2026 at 5:47 pm
  • Editorial Team
    Editorial Team added an answer The first thing to try is GetNewBindingList(), but this thread:… May 11, 2026 at 5:47 pm

Related Questions

I am working on a project that has been running for a long period
I'm working at a company that does several releases to production every year and
I am working on localization for an app where custom patterns are used to
Whenever I have a library that use across different websites/ applications I've always just

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.