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

Challenge: Apply the publish/subscriber pattern - PHP Tutorial

From the course: PHP: Design Patterns

Start my 1-month free trial

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.

Contents