0

Hi, this is a super basic question but my classes are not working the way I expect them to. I am a CS student in my second year so go easy on me! The only other language I know is Java. Here is my class, called class.Team.php (represents a team).

<?php
class Team
{
    private $teamId='';
    private $teamName='Tyler';
    private $teamCity='';
    private $homeField='';
    private $headCoach='';
    private $mascot='';
    private $wins=0;
    private $losses=0;
    private $roster;

    function display(){

        return $teamName;
    }
}

?>

So when I call the display() method it should return a string (hardcoded as "tyler). Here is my test script. It is simply displaying nothing. A blank white page. Am I missing something??

<?php
    include ('class.Team.php'); 
    $um = new Team;  
    $string = $um->display();
    print ($string);
?>

THANKS!

3
Contributors
4
Replies
7
Views
5 Years
Discussion Span
Last Post by Squidge
0

Change the function this way:

function display(){

    return $this->teamName;
}

You need to refer to the object->property; this refers to the current object.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.