本篇文章主要介绍php代理模式详解及案例,感兴趣的朋友参考下,希望对大家有所帮助。
代码如下:
<?php // 代理模式 index.php header("Content-Type:text/html;charset=utf-8"); require_once "Proxy.php"; // 代理对象 $obj = new Proxy("专业的事情"); // 展示 $obj->Show(); [php] view plain copy <?php // 代理接口 interface IProxy { function Show(); } // 真实对象 Class Profession implements IProxy { /** * 私有 专业事情 * @var string */ private $Things; /** * 构造方法 * @access public * @param string $things 专业的事情 */ function __construct($things){ $this->Things = $things; } /** * 真实对象的展示方法 * @access public */ function Show(){ echo "专业的人才做{$this->Things}"; } } // 代理对象 Class Proxy implements IProxy { /** * 私有真实对象变量 * @var object */ private $Pro; /** * 构造方法 * @access public * @param string $things 专业的事情 */ function __construct($things){ $this->Pro = new Profession($things); } /** * 代理对象的展示方法 * @access public */ function Show(){ $this->Pro->Show(); } }
输出结构:
专业的人才做专业的事情
相关推荐:
立即学习“PHP免费学习笔记(深入)”;
以上就是PHP代理模式详解及案例的详细内容,更多请关注php中文网其它相关文章!
PHP怎么学习?PHP怎么入门?PHP在哪学?PHP怎么学才快?不用担心,这里为大家提供了PHP速学教程(入门到精通),有需要的小伙伴保存下载就能学习啦!
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号