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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T03:29:36+00:00 2026-05-11T03:29:36+00:00

I have quite a lot of PHP view files, which I used to include

  • 0

I have quite a lot of PHP view files, which I used to include in my controllers using simple include statements. They all use methods declared in a view class which they get like $view->method(); However I recently decided that it would be better if the including would also be done by this view class. This however changes the scope of the included file so that $view is no longer defined. Here is a code example:

in someViewFile.php (BOTH siuations)     <html>     <head><title><?php echo $view->getAppTitle(); ?></title>     etc. OLD SITUATION in controller:     $view = new view;     include('someViewFile.php'); //$view is defined in someViewFile.php NEW SITUATION in controller:     $view = new view;     $view->show('someViewFile'); //$view is not defined in someViewFile.php 

Right now I hacked my way around the problem using this in the view class:

public function show($file){     $view = &$this;     include($file.'.php'); } 

Is there anyway to declare the scope of the inluded file or is this the best way of solving the problem?

These examples are off coarse simplified.

  • 1 1 Answer
  • 4 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-11T03:29:36+00:00Added an answer on May 11, 2026 at 3:29 am

    You can’t change include() scope, no, so your method is probably about as good as it gets in the situation you’re describing. Though I’d skip the ugly PHP4-compat ampersand, myself.

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

Sidebar

Related Questions

I have quite a lot of music files but their title attributes have the
I have a PHP application that relies on session variables quite a lot. After
Suppose I have a lot of math calculations which are quite tedious to implement
I'm mainly a c/c++ guy. I have done quite a lot of PHP stuff,
I have worked quite a lot with javascript but yesterday, I started using node.js.
we have quite a lot of RPG-programs here, and we do a lot of
I have quite a lot of C++ legacy code modules from my colleagues, unfortunately
I'm a beginner at Andengine, but I have read quite a lot of tutorials
I have a test file that contains tests taking quite a lot of time
I seem to run into this situation quite a lot and have yet to

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.