Last active
February 12, 2022 21:11
-
-
Save Kcko/71fbb90ee5a1b4dd3b4342b15fb34f12 to your computer and use it in GitHub Desktop.
This file contains 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 | |
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