PHP Classes

File: README.md

Recommend this page to a friend!
  Classes of Lucas de Oliveira  >  PHP Copy Object Properties to Another  >  README.md  >  Download  
File: README.md
Role: Documentation
Content type: text/markdown
Description: Documentation
Class: PHP Copy Object Properties to Another
Copy the values of attributes to another object
Author: By
Last change:
Date: 1 year ago
Size: 2,044 bytes
 

Contents

Class file image Download

CopyObjectAttributesValues

Build Status Code Coverage Code Quality License MIT Packagist

Simple helper to copy attributes values with the same name from one object to an other.

Installation

composer require deoliveiralucas/copy-object-attributes-values

Usage

use CopyObjectAttributesValues\CopyObjectAttributesValues;

class ObjectA {
    private $attributeA = 'ObjectA_AttrA';
    private $attributeB = 'ObjectA_AttrB';
}
class ObjectB {
    private $attributeA = 'ObjectB_AttrA';
    private $attributeB = 'ObjectB_AttrB';
    private $attributeC = 'ObjectB_AttrC';
}

$objectA = new ObjectA();
$objectB = new ObjectB();

CopyObjectAttributesValues::from($objectA)->to($objectB);

var_dump($objectB);

/*
Output:
class ObjectB#2 (3) {
  private $attributeA =>
  string(13) "ObjectA_AttrA"
  private $attributeB =>
  string(13) "ObjectA_AttrB"
  private $attributeC =>
  string(13) "ObjectB_AttrC"
}
*/

Contributing

Please see CONTRIBUTING for details.

License

CopyObjectAttributesValues is released under the MIT License. Please see License File for more information.


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