Has Parent: Trait to assign on object as parent of another

Recommend this page to a friend!
  Info   Documentation   View files (5)   Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 63 All time: 9,722 This week: 289
Version License PHP version Categories
has-parent 0.0.2GNU General Publi...5.6PHP 5, Language, Traits
Description Author

This package provides a trait to assign on object as parent of another.

It provides a function that takes one object and assigns it as the parent of another object of another class.

When the same function is called without parameters it returns the previously assigned parent object, so the parent object functions and variables can be accessed.

Innovation Award
PHP Programming Innovation award nominee
September 2016
Number 13
PHP provides means to reuse classes that extend functionality of others, but that requires that classes be defined as sub-classes.

If you want to combine objects of different classes, PHP does not provide a built-in way for that.

This package provides a trait that can be used to emulate inheritance between objects of different classes.

Manuel Lemos
Picture of magog
  Performance   Level  
Name: magog <contact>
Classes: 3 packages by
Country: Russian Federation Russian Federation
Age: 43
All time rank: 282377 in Russian Federation Russian Federation
Week rank: 762 27 in Russian Federation Russian Federation
Innovation award
Innovation award
Nominee: 2x




This trait assigns parent to a class.


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


Package depends on __deferred-exceptions__ package.

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


composer require seotils/has-parent



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!

File Role Description
src (2 directories)
composer.json Data Auxiliary data
LICENSE Lic. License text
README.md Doc. Class source

  Files  /  src  
File Role Description
Interfaces (1 file)
Traits (1 file)

  Files  /  src  /  Interfaces  
File Role Description
   IHasParent.php Class Class source

  Files  /  src  /  Traits  
File Role Description
   HasParent.php Class Class source

has-parent-2016-09-07.zip 14KB
has-parent-2016-09-07.tar.gz 13KB
Install with Composer
Needed packages  
Class DownloadWhy it is needed Dependency
Deferred Exceptions .zip .tar.gz It`s a part of the package Required
 Version Control Unique User Downloads Download Rankings  
This week:0
All time:9,722
This week:289

For more information send a message to info at phpclasses dot org.