Hi
I am trying to teach myself PHP best practice. As a C++ programmer I hate global variables so I am planning to implement this in my next project. Previously, I have declared global PHP variables and then accessed them directly from HTML. But as already stated, global’s are bad news.
So this time I am planning implementing my next project as follows:
test.php
class TestClass
{
// Function initialises the entire procedure
public function startTest(){
$test = array("Volvo","BMW","Toyota");
return $test;
}
}
html_output.php
<!DOCTYPE html>
<html>
<head>
<?php
include ('test.php');
$forecast = new TestClass();
$dataArray = $forecast->startTest();
?>
</head>
<body>
<p><?php echo $dataArray[0] ?></p>
<p><?php echo $dataArray[1] ?></p>
<p><?php echo $dataArray[2] ?></p>
</body>
</html>
Is this better than using global’s? Or. is there a better way of achieving this?
Many Thanks