コード例 #1
0
ファイル: oo.php プロジェクト: anatai/manray
    function age($a)
    {
        $this->age = (string) $a;
    }
    function feelings($f)
    {
        $this->feelings = $f;
    }
    //$this refers to the currently occupied class
    function welcome()
    {
        echo 'hello ' . $this->name . ' you are ' . $this->age . ' years old and you are feeling ' . $this->feelings . '<br>';
    }
    function introduce($person)
    {
        echo 'hello ' . $person->name . ', I am ' . $this->name . '<br>';
    }
}
$person = new person();
$person->name('steve');
$person->age(28);
$person->feelings('let down');
// $person->welcome();
//sets the same class above to person and person2 both using their own isolated scope (they use the same set of functions)
$person2 = new person();
$person2->name('Chris');
$person2->age('103');
$person2->feelings('overwhelmed');
// $person2->welcome();
$person2->introduce($person);