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!

Change your function

function display(){
        return $this->teamName;
    }

Change the function this way:

function display(){

    return $this->teamName;
}

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

@Squidge

You got me for few seconds :-)

@broj1

:)

Although you did give a clear explaination :)

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.