I'm starting to learn PHP and OOP and I'm stuck. I have 3 different php files that I paste below. The particular problem is stated after the code:
File1.php :
<?php
class Page{
public $intro;
public $article;
}
$TD = new Page($intro, $article);
$TD->intro="I'm the intro";
$TD->article="I'm an article";
?>
File2.php
<?php
function test($page){
switch($page){
case "A":
include "file1.php";
break;
case "B":
include "anotherfile.php";
break;
}
}
?>
File3.php (the one that has to print something):
<?php
$page="A";
include "file2.php";
test($page);
echo $TD->intro;
echo $TD->article;
?>
I can't echoing (says that $TD is undefined), but I've been testing and it seems that it's effectively loading the file1.php (where the $TD object is defined). Furthermore, if I paste the problematic echoes in the file1.php and loading this page, the echoes work.
I suppose that it's something obvious but I am not capable of figure it out yet.
Thanks in advance for your response and for reading this to the end!!! :)