Advertisement

04.28.2008 at 09:53AM PDT, ID: 23359325
[x]
Attachment Details

Accessing variables declared in an included file

Asked by mb2297 in PHP Scripting Language, PHP for Windows

Tags: PHP, 4

Hi experts,

This should be fairly simple. In my PHP app, I'm using a file called PATHS.php to store common data that I want available to different PHP classes / functions / includes.

PATHS.php looks like this:

<?php
      $FOO = 'foobar';
      $OOF = 'barfoo';
?>

and in my other files I do this:


<?php
      include('PATHS.php');
      ...
      echo $FOO;            //works
?>


<?php
      include('PATHS.php');
      ...
      class Something extends SomethingElse
      {
            function doSomething() {
                  echo $FOO;      //doesn't work
                  global $FOO;
                  echo $FOO;      //doesn't work either
            }
      }
?>

How should I access those variables within the second file?

Many thanks,
Matt.Start Free Trial
 
 
[+][-]04.28.2008 at 10:00AM PDT, ID: 21455615

View this solution now by starting your 7-day free trial. Setting up your free trial is quick, easy, and secure. We will return you to this solution, unlocked, when you're done.

 

About this solution

Zones: PHP Scripting Language, PHP for Windows
Tags: PHP, 4
Sign Up Now!
Solution Provided By: hernst42
Participating Experts: 2
Solution Grade: B
 
 
[+][-]04.28.2008 at 10:01AM PDT, ID: 21455618

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.28.2008 at 10:22AM PDT, ID: 21455791

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 10:26AM PDT, ID: 21455816

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 10:34AM PDT, ID: 21455887

Assisted solutions are selected by the member who asked the question as a comment that contributed to their question's solution.

Start your 7-day free trial to view this Assisted Solution or ask the Experts your question.

 
[+][-]04.28.2008 at 10:37AM PDT, ID: 21455914

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 10:41AM PDT, ID: 21455940

At Experts Exchange, members can ask their questions to thousands of technology professionals, also known as Experts. Experts compete and collaborate to answer those questions by leaving comments like this one.

Start your 7-day free trial to view this Expert Comment or ask the Experts your question.

 
[+][-]04.28.2008 at 10:55AM PDT, ID: 21456040

Often, when Experts are collaborating with members who have asked questions, they will request additional information about the problem. Askers respond with an author comment like this one.

Start your 7-day free trial to view this Author Comment or ask the Experts your question.

 
 
Loading Advertisement...
20080716-EE-VQP-32 / EE_QW_2_20070628