seotils/has-parent

该特性允许设置和获取实例的父类。

0.0.3 2016-09-06 20:30 UTC

This package is not auto-updated.

Last update: 2024-09-14 18:37:01 UTC


README

描述

此特性将父类分配给一个类。

许可证

HasParent 是开源软件,采用 [GPL-3.0] 许可 (https://gnu.ac.cn/licenses/gpl-3.0.en.html)。

要求

该软件包依赖于 deferred-exceptions 软件包。

  1. GitHub

  2. Composer (packagist.org)

  3. PHPClasses

安装

composer require seotils/has-parent

用法

<?php

namespace My;

use Seotils\Traits\HasParent;

/**
 * Parent class
 */
class A {
  public function time(){
    return date('Y-m-d H:i:s');
  }
}

/**
 * Class with HasParent trait
 */
class B {
  use HasParent;
}

// Usage

$a = new A();
$b = new B();

// Assign and use parent class
echo $b->parentClass( $a )->time();

// Or step by step

// Assign parent class
$b->parentClass( $a );

// Use parent class
echo $b->parentClass()->time();

这就结束了!