0

I have a class that includes a file with some variables. How can i use these variables after including them?

My variables.php file:

<?php
$variable = 'Hello World';

My test file (test.php):

<?php
class test {
    public function __construct() {

    }

    public function includeFile($file) {
        include($file);
    }
}

$test = new test();
$test->includeFile('variables.php');

echo $variable;

The code above gives the following error: Notice: Undefined variable: $variable in C:\xampp\htdocs\test.php

EDIT: I'd like to be able to obtain the variable multiple times outside the class so an echo $variable inside includeFile would not be the solution i'm looking for. Neither does my code know the variables that can be called upon so globalizing would not be the solution either that i'm looking for.

Mart
  • 475
  • 4
  • 21

0 Answers0