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 ... |
Get PHP Advanced for the World Wide Web: Visual QuickPro Guide now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.