Skip to content

Instantly share code, notes, and snippets.

@Kcko
Last active February 12, 2022 21:11
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 Kcko/71fbb90ee5a1b4dd3b4342b15fb34f12 to your computer and use it in GitHub Desktop.
Save Kcko/71fbb90ee5a1b4dd3b4342b15fb34f12 to your computer and use it in GitHub Desktop.
<?php
class User {
protected $name;
protected $timeline = array();
public function __construct($name)
{
$this->name = $name;
}
public function addTweet(Tweet $tweet)
{
$this->timeline[] = $tweet;
}
}
class Tweet {
protected $id;
protected $text;
protected $read;
public function __construct($id, $text)
{
$this->id = $id;
$this->text = $text;
$this->read = false;
}
public function __invoke($user)
{
$user->addTweet($this);
return $user;
}
}
$users = array(new User('Ev'), new User('Jack'), new User('Biz'));
$tweet = new Tweet(123, 'Hello world');
$users = array_map($tweet, $users);
var_dump($users);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment