Can anyone explain why this isnt working?
I have two files index.php and include.php, the code for both are below, index includes the include.php but it doesnt output anything.
Include.php

<?php
class test {
var $two;
$this->two = 'variable 2';
function test1() {
$one = 'variable 1';
$testvar1 = $this->two;
$testvar1 .= $one;
return $testvar1;
}
function test2() {
 global $three;
 $three = 'variable three';
}

}
$test = new test;
?>

Index.php

<?php
include 'include.php';
$mine = $test->test1();
echo $mine;
$test->test2();
echo $three
echo "<html>me test</html>";
?>

Recommended Answers

All 3 Replies

Try this:
instead of:

$test = new test;

try:

$test = new test();

Nope that doesnt work :(

sorry, should have looked closer. your missing a semicolon on line 6 of your index.php file. Also, you can't use $this outside of a method in a class. If you want $this->two to be equal to 'variable 2', you need to do that in your declaration.

private $two = 'variable 2';
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.