Last Updated | | Ratings | | Unique User Downloads | | Download Rankings |
2022-10-21 (1 month ago) | | Not enough user ratings | | Total: 68 This week: 1 | | All time: 10,082 This week: 491 |
|
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
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 |
| |
|
|
Innovation award
Nominee: 2x |
|
Details
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.
-
GitHub:
* seotils/deferred-exceptions
-
Composer (packagist.org):
* seotils/deferred-exceptions
-
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!
|
Applications that use this package |
|
No pages of applications that use this class were specified.
If you know an application of this package, send a message to the author to add a link here.