Skip to content

Commit

Permalink
Add Trait tip
Browse files Browse the repository at this point in the history
  • Loading branch information
kayw-geek authored Mar 21, 2022
1 parent 28cfd54 commit 23784ca
Showing 1 changed file with 24 additions and 1 deletion.
25 changes: 24 additions & 1 deletion languages/php.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 6,7 @@
*/
class NormalClass extends AbstractClassName implements InterfaceName
{

// 引用 Trait (为 PHP 提供多继承的能力,可理解为代码复制)
use TraitName;

// --> 类属性类型 <--
Expand Down Expand Up @@ -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();
}
}

0 comments on commit 23784ca

Please sign in to comment.