Basic class help

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
mcmcom
Forum Newbie
Posts: 14
Joined: Thu Jan 31, 2008 7:23 am

Basic class help

Post 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
User avatar
Zoxive
Forum Regular
Posts: 974
Joined: Fri Apr 01, 2005 4:37 pm
Location: Bay City, Michigan

Re: Basic class help

Post by Zoxive »

Code: Select all

function returnValue(){
  return $this->test;
}
User avatar
BDKR
DevNet Resident
Posts: 1207
Joined: Sat Jun 08, 2002 1:24 pm
Location: Florida
Contact:

Re: Basic class help

Post 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:
Post Reply