不在类定义里赋值可以这么写

来源:3-3 类的定义和实例化-PHP面向对象编程

氓风

2015-05-13 14:08

<?php

class NbaPlayer{

public $name;

public $height;

public $weight;

public $team;

public $playerNumber;

public function run(){

echo "Running\n";

}

public function jump(){

echo "Jumping\n";

}

public function dribble(){

echo "Dribbling\n";

}

public function shoot(){

echo "Shooting\n";

}

public function dunk(){

echo "Dunking\n";

}

public function pass(){

echo "Passinging\n";

}

}


$jordan = new NbaPlayer();

$jordan->name="Jordan";

$jordan->height="198cm";

$jordan->weight="92kg";

$jordan->team="Bull";

$jordan->playerNumber="23";


echo $jordan->name."\n";

?>


写回答 关注

1回答

  • qq_灰尘_0
    2015-10-14 15:44:20

    恩恩,这才是真正的类

PHP面向对象编程

从容应对面试官的知识宝典,带你握面向对象的最重要的核心能力

70146 学习 · 361 问题

查看课程

相似问题