Home  >  Article  >  Backend Development  >  Introduction to php object dependencies

Introduction to php object dependencies

不言
不言Original
2018-07-04 15:38:492163browse

This article mainly introduces the introduction of PHP object dependencies, which has certain reference value. Now I share it with everyone. Friends in need can refer to it

Methods through constructors

 1 action = $a;
 17     }
 18     //通过方法访问类中的私有属性
 19     public function getaction()
 20     {
 21         $this->action->playing();22     }
 23 }
 24 
 25 $ply = new play();
 26 $vid = new video($ply);
 27 $vid->getaction();//输出I can playing

Through attributes

action = $a;
    }    //通过方法访问类中的私有属性
    public function getaction()
    {       return $this->action->playing();
    }
}$ply = new play();//实例化play类后面做参数
$vid = new video();
$vid->action = $ply;//当访问video为定义的属性值时会调用__set()方法(不懂的可以看看php的魔术方法)
$vid->getaction();//输出I can playing

The above is the entire content of this article. I hope it will be helpful to everyone's learning. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

php code to traverse all files and sub-files in a folder

php remove project file BOM headers in batches Methods

The above is the detailed content of Introduction to php object dependencies. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn