Using the static keyword


show more Using the static keyword provides you with in-depth training on Developer. Taught by Jon Peck as part of the Object-Oriented Programming with PHP show less
please wait ...

Using the static keyword

Up to this point, the only way we've used classes is by instantiating, which can get a bit unwieldy. In this chapter, I'm going to introduce the concept of the static keyword, which gets around this limitation. I'll then demo how to access class contents without instantiation, set values that never change, and even how to create a method that doesn't require instantiation. Finally, we'll put it all together, and create a custom database class. But before we do that, let's start with the basics, avoiding instantiating. Sometimes, it's useful to access a property or method of a class without the overhead of actually instantiating an object.

Depending on the class, that instantiation might include connections to a database or third-party service, which can drag down performance when all you needed to do was get a default value. Also, before the release of PHP 5.3, the only way a developer could prevent a function or variable from having global scope was to declare i...

Using the static keyword
Video duration: 3m 36s 1h 57m Intermediate Updated Apr 10, 2013

Viewers:

Using the static keyword provides you with in-depth training on Developer. Taught by Jon Peck as part of the Object-Oriented Programming with PHP

Subject:
Developer
Software:
PHP
Author:
please wait ...