Page 1 of 1

Basic class help

Posted: Thu Jan 31, 2008 3:18 pm
by mcmcom
hi all this is for PHP 4.

whats wrong with this

Code: Select all

 
<?php
 
class TestClass{
    
    var $test = "HELLO!"; 
    
    function returnValue(){
        return $test;
    }
    
}
 
?>
 
//calling from another page 
<?php
 
include 'Testclass.php';
 
if(isset($_POST['Submit'])) {
    $mytest = new TestClass(); 
    $myVar = $mytest->returnValue(); 
    echo $myVar; 
}
 
 
?>
 
I get the error "Ivalid Expression" both in the included class and obviouslly the calling variable "$myVar". how come it does not return the word "HELLO" ?
thanks in advance,
mcm

Re: Basic class help

Posted: Thu Jan 31, 2008 3:43 pm
by Zoxive

Code: Select all

function returnValue(){
  return $this->test;
}

Re: Basic class help

Posted: Thu Jan 31, 2008 5:03 pm
by BDKR
Looks like you need to learn how to read the error responses that come back from the engine. I'm pretty positive that it gave you a line number. :wink: