From 28cfd54f505c6a1482c3799bf06dea2b844bb78f Mon Sep 17 00:00:00 2001 From: Kay W Date: Mon, 21 Mar 2022 14:49:54 +0800 Subject: [PATCH 1/2] fix typo --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index fb2fede..6615fe9 100644 --- a/README.md +++ b/README.md @@ -21,7 +21,7 @@ - [Bash](languages/bash.sh) - [JavaScript](languages/javascript.md) - [Go](languages/golang.go) -- [Php](languages/php.php) +- [PHP](languages/php.php) - [VimScript](languages/vimscript.md) - [Python](languages/python.md) - [Lua](languages/lua.lua) From 23784caba07dec4815978e1ef8e0b69a80601040 Mon Sep 17 00:00:00 2001 From: Kay W Date: Mon, 21 Mar 2022 16:34:46 +0800 Subject: [PATCH 2/2] Add Trait tip --- languages/php.php | 25 ++++++++++++++++++++++++- 1 file changed, 24 insertions(+), 1 deletion(-) diff --git a/languages/php.php b/languages/php.php index 4449322..b55a0f5 100644 --- a/languages/php.php +++ b/languages/php.php @@ -6,7 +6,7 @@ */ class NormalClass extends AbstractClassName implements InterfaceName { - + // 引用 Trait (为 PHP 提供多继承的能力,可理解为代码复制) use TraitName; // --> 类属性类型 <-- @@ -247,3 +247,26 @@ abstract class AbstractClassName abstract function abstractFunction(Type $var = null): Type; } + +/** + * Trait + * 提供代码复用能力、多继承能力 + */ +trait Logger +{ + public function log($message) + { + return $message; + } +} + +class WriteLog +{ + use Logger; + + public function main() + { + return $this->log(); + } +} +