Created
August 7, 2018 12:56
-
-
Save tabuna/3982e8079bcfa3869190f6c03f82b34d to your computer and use it in GitHub Desktop.
PHP Bing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
declare(ticks=1); | |
/** | |
* Class Bind | |
*/ | |
class Bind | |
{ | |
/** | |
* @param $object | |
* @param array $attributes | |
*/ | |
public function bindToAttributes($object, array $attributes) | |
{ | |
register_tick_function(function () use ($object, $attributes) { | |
foreach ($attributes as $attribute) { | |
$this->$attribute = $object->$attribute; | |
} | |
}); | |
} | |
} | |
/** | |
* Class User | |
*/ | |
class User | |
{ | |
/** | |
* @var string | |
*/ | |
public $name = 'Alexandr Chernyaev'; | |
/** | |
* @param $name | |
*/ | |
public function reName($name) | |
{ | |
$this->name = $name; | |
} | |
} | |
// Главный бинд | |
$baseUser = new User(); | |
$user1 = new Bind(); | |
$user2 = new Bind(); | |
var_dump($user1, $user2); | |
$user1->bindToAttributes($baseUser, ['name']); | |
$user2->bindToAttributes($baseUser, ['name']); | |
$baseUser->name = 'Alena'; | |
var_dump($user1, $user2); | |
$baseUser->name = 'Maxim'; | |
var_dump($user1, $user2); | |
$baseUser->reName('tabuna'); | |
var_dump($user1, $user2); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment