Add Trait tip

pull/91/head
Kay W 3 years ago committed by GitHub
parent 28cfd54f50
commit 23784caba0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -6,7 +6,7 @@
*/ */
class NormalClass extends AbstractClassName implements InterfaceName class NormalClass extends AbstractClassName implements InterfaceName
{ {
// 引用 Trait (为 PHP 提供多继承的能力,可理解为代码复制)
use TraitName; use TraitName;
// --> 类属性类型 <-- // --> 类属性类型 <--
@ -247,3 +247,26 @@ abstract class AbstractClassName
abstract function abstractFunction(Type $var = null): Type; 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();
}
}

Loading…
Cancel
Save