From the course: PHP: Object-Oriented Programming

Unlock this course with a free trial

Join today to access over 25,500 courses taught by industry experts.

Solution: Static references

Solution: Static references - PHP Tutorial

From the course: PHP: Object-Oriented Programming

Solution: Static references

(bright upbeat music) - [Instructor] I hope that you had success in completing the static references challenge. Now, let me show you the solution that I came up with. The first thing I did was set up for the challenge which meant going into challenge_03.php and grabbing both the Bicycle class and the Unicycle class and putting those into a new file called challenge_04.php. Then I could start the different parts of the challenge. The first thing was to add a new property called instance_count to make it a static property and also of course I want to make it public so that it has visibility. It's always the best practice to have visibility in front of this. I also gave it a good default value, which is zero. So we'll start this counter at zero. And every time we create a new instance we're going to increment that counter. We're also going to define a new method. It's a static method. I've also said that it should be…

Contents