PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of magog   Has Parent   README.md   Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Class source
Class: Has Parent
Trait to assign on object as parent of another
Author: By
Last change: Update of README.md
Date: 1 year ago
Size: 1,172 bytes
 

Contents

Class file image Download

HasParent

Description

This trait assigns parent to a class.

License

HasParent is open-sourced software licensed under the GPL-3.0.

Requirements

Package depends on __deferred-exceptions__ package.

  1. GitHub: * seotils/deferred-exceptions
  2. Composer (packagist.org): * seotils/deferred-exceptions
  3. PHPClasses: * Deferred Exceptions

Install

composer require seotils/has-parent

Usage

<?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();

That`s all!