PHP code example of kenny1911 / php-clone-with

1. Go to this page and download the library: Download kenny1911/php-clone-with library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

kenny1911 / php-clone-with example snippets


use function Kenny1911\CloneWith\clone_with;

class Post
{
    /** @var string */
    private $title;
    
    /** @var string */
    private $author;
    
    public function __construct(string $title, string $author)
    {
        $this->title = $title;
        $this->author = $author;
    }
    
    public function getTitle(): string
    {
        return $this->title;
    }
    
    public function getAuthor(): string
    {
        return $this->author;
    }
}

$post = new Post('Foo', 'Author');

$post2 = clone_with($post, ['title' => 'Bar']);

echo $post2->getTitle(); // Bar