From the course: PHP: Design Patterns
Unlock the full course today
Join today to access over 22,600 courses taught by industry experts or purchase this course individually.
Challenge: Apply the publish/subscriber pattern - PHP Tutorial
From the course: PHP: Design Patterns
Challenge: Apply the publish/subscriber pattern
- While the challenge code looks a lot like our example, we're going to add one kink to the mix. We want to pass along a value into our subscribers. If we look at the challenge code itself, this is what it looks like. You can see we're passing i in here and incrementing it each time. And this is what it looks like in the browser. So you can see, we're incrementing the count, and displaying each component name, one by one. When you're working on this solution, be careful of that count, make sure it's what you expect. And if you're unsure on how to build in a dispatcher, feel free to copy one from the After folder that we looked at earlier. I fully expect this challenge to take you a little longer than most. So take your time and get it right. The one hint then I'll say is remember the scope of your variables and when they get modified. When you write or see a particular solution check out the next video in the solutions folder.
Practice while you learn with exercise files
Download the files the instructor uses to teach the course. Follow along and learn by watching, listening and practicing.
Contents
-
-
-
-
-
-
-
-
-
-
(Locked)
Introducing the publish/subscriber pattern2m 4s
-
(Locked)
Exploring a use case for the publish/subscriber pattern1m 57s
-
(Locked)
The publish/subscriber pattern in action1m 6s
-
(Locked)
Challenge: Apply the publish/subscriber pattern51s
-
(Locked)
Solution: Apply the publish/subscriber pattern1m 4s
-
(Locked)
-
-
-
-