O'Reilly logo

PHP Advanced for the World Wide Web: Visual QuickPro Guide by Larry Ullman

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Using Class Functions Without Instances

There is a way in PHP 4 (not available in version 3) to make use of a class's method without having to create an instance of the class. This can be useful if there is a function you would like to use, but you do not need the whole class that the function is in. The syntax for doing this (assuming a class called ClassName contains a method named Method) is:

ClassName::Method(); 

As an example of this, you'll use the DetermineLinks() function to create a site map page, without creating an instance of HtmlNavTemplate—the class that defines the DetermineLinks() method.

To use the :: operator:

1.
Create a new PHP document in your text editor (Script 2.12).
<?php 
Script 2.12. The sitemap.php script makes ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required