1. <?php
    2. class Person{
    3. private $name;
    4. private $weight;
    5. private $height;
    6. public function __construct($name, $weight, $height){
    7. $this->name=$name;
    8. $this->weight=$weight;
    9. $this->height=$height;
    10. }
    11. public function getName() {
    12. echo $this->name;
    13. }
    14. public function getWeight() {
    15. echo "体重是".$this->weight."kg。";
    16. }
    17. public function getHeight() {
    18. echo "身高是".$this->height."cm,";
    19. }
    20. }
    21. $person = new Person('明明', '51.5', '165');
    22. echo $person->getName();
    23. echo '的';
    24. echo $person->getHeight();
    25. echo $person->getWeight();
    26. ?>