Question

I'm fairly new with classes, and I've been looking online for some kind of tutorial on this, but unfortunately I've been unsuccessful at finding a solution. Any help you guys could give me would be much appreciated.

I have 2 files.

1) variables.inc.php:

$myvar = "hello world";

2) myclass.php:

include("variables.inc.php");
class myClass {

    function doSomething() {
        echo "myvar: $myvar";
    }
}

The problem: $myvar returns empty. I tried adding this line between function doSomething() { and echo...: global $myvar; But it doesn't seem to work that way either. Any suggestions?

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top