Skip to content

Instantly share code, notes, and snippets.

@Kcko

Kcko/wakeup.php

Created Nov 19, 2020
Embed
What would you like to do?
<?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
You can’t perform that action at this time.