PHP100 2019-03-27
代码如下:
<? class employee{ private $sal=3000; //protected $sal=3000; public function getSal(){ return $this->sal; } } class Manager extends employee { protected $sal=5000; public function getParentSal(){ //这里返回的是父类的private属性. return parent::getSal(); } } $manager = new Manager(); echo "PHP ".phpversion()."<br>"; echo $manager->getSal(); echo "<br>"; echo "parent's \$sal ".$manager->getParentSal(); ?>
代码如下:
PHP 5.3.8 3000 parent's $sal 3000
代码如下:
<? class employee{ //private $sal=3000; protected $sal=3000; public function getSal(){ return $this->sal; } } class Manager extends employee { protected $sal=5000; public function getParentSal(){ //这里返回的是父类的private属性. return parent::getSal(); } } $manager = new Manager(); echo "PHP ".phpversion()."<br>"; echo $manager->getSal(); echo "<br>"; echo "parent's \$sal ".$manager->getParentSal(); ?>
代码如下:
PHP 5.3.8 5000 parent's $sal 5000
代码如下:
<? class employee{ private $sal=3000; public function getSal(){ return $this->sal; } } class Manager extends employee { private $sal=5000; //重写过的方法 public function getSal(){ return $this->sal; } public function getParentSal(){ //这里返回的是父类的private属性. return parent::getSal(); } } $manager = new Manager(); echo "PHP ".phpversion()."<br>"; echo $manager->getSal(); echo "<br>"; echo "parent's \$sal ".$manager->getParentSal(); ?>
代码如下:
PHP 5.3.8 5000 parent's $sal 3000
代码如下:
<? class employee{ private $sal=3000; public function getSal(){ return $this->sal; } } class Manager extends employee { protected $sal=5000; public function getParentSal(){ return $this->sal; } } $manager = new Manager(); echo "PHP ".phpversion()."<br>"; echo $manager->getSal(); ?>
代码如下:
PHP 5.3.8 3000
代码如下:
<? class employee{ protected $sal=3000; public function getSal(){ return $this->sal; } } class Manager extends employee { protected $sal=5000; public function getParentSal(){ return $this->sal; } } $manager = new Manager(); echo "PHP ".phpversion()."<br>"; echo $manager->getSal(); ?>
代码如下:
PHP 5.3.8 5000
<?php. if (!empty($_POST)) {. $data1 = $_POST["data1"];$data2 = $_POST["data2"];$fuhao = $_POST["fuh