Skip to content

Instantly share code, notes, and snippets.

@kobus1998
Created August 8, 2019 07:06
Show Gist options
  • Save kobus1998/93eb4e952f2bb0bdc9e8faa1b9db39be to your computer and use it in GitHub Desktop.
Save kobus1998/93eb4e952f2bb0bdc9e8faa1b9db39be to your computer and use it in GitHub Desktop.
clonable
<?php
class clonable
{
public function __construct(...$args)
{
$this->args = func_get_args();
}
public function __clone()
{
return new self(...$this->args);
}
}
class a extends clonable
{
public function __construct($a, $b)
{
parent::__construct($a, $b);
$this->a = $a;
$this->b = $b;
}
}
$a1 = new a(1, 2);
$a2 = clone $a1;
$a2->b = 3;
var_dump($a1, $a2);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment