类的声明及类之间的调用与传递,输出结构

<?php
/**
 * Created by PhpStorm.
 * User: Administrator
 * Date: 2016/5/14
 * Time: 10:41
 */

class lifeThing{

    protected $plant="zhiw";

    protected $animal="dongwu";

}

class Animal{
    //动物属性
    public $name='';
    public $color='';
    protected $sex="";
    protected  $age="";

    protected $footer=[1,2];
    protected $object="";

    //动物的行为

    public function runAction(){
        echo 'I can run in anywhere';
    }

    public function  voiceAction($language){
        echo 'I can speak '.$language;
    }
    //传入一个对象
    public function setObject($obj){
      $this->object=$obj;
    }
    //返回一个对象
    public function getObject(){
        return $this->object;
    }


}

$object=new lifeThing();
$animal=new Animal();
$animal->setObject($object);
//输出展示
var_dump($animal);
var_dump($animal->getObject());

 

2,输出结果

posted @ 2016-05-14 11:17  lokou  阅读(210)  评论(0编辑  收藏  举报