Skip to content

Instantly share code, notes, and snippets.

@tabuna
Created August 7, 2018 12:56
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save tabuna/3982e8079bcfa3869190f6c03f82b34d to your computer and use it in GitHub Desktop.
Save tabuna/3982e8079bcfa3869190f6c03f82b34d to your computer and use it in GitHub Desktop.
PHP Bing
<?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