Here is my problem/question:
Say I have a class stored in a php file called 'myclass.php' and I have my main index php page 'index.php'.
In that index.php page I include the 'myclass.php' file and create a variable as a new object of the class from myclass.php.
However in the index page there are multiple php breaks <?php ?> <?php ?>, how can I use the variable that is of my class throughout the entire page?
myclass.php:
class MyClass {
function MyClass() {
...
}
function foo() { ... }
function bar() { ... }
}
index.php
<html>
<head> ... </head>
<body>
<?php
include_once('myclass.php');
$thing = new MyClass();
?>
...
<?php
$thing->foo();
?>
...
<?php
$thing->bar();
?>
</body>
</html>
When trying to call $thing outside of the first php block I get an 'undefined variable' error. What is the scope of this variable, how can I have it shared amoungst all the php code blocks?