How to Reference PHP Class Member Functions

PHP classes provide programmers with reusable code that defines a section of a particular program. The class member functions execute statements within a class, such as a function in a "customer" class that provides information about a customer. You must create a variable that calls the class, then call the member function that runs the class code.

Instructions

    • 1

      Right-click the PHP file you want to use to call your class. Select "Open With," then double-click the PHP editor you used to create the class.

    • 2

      Create a variable and set it to the class name. The following code creates a PHP class variable:

      $class = 'myclass';

      Replace "myclass" with the name of your own PHP class.

    • 3

      Reference the PHP class member function. A class can contain several member functions, so you must know the function name to call it. Type the following code to reference the function:

      $class::viewCustomer();

      This code uses the class variable and calls the member function named "viewCustomer()." Replace "viewCustomer" with your own function name.

    • 4

      Save the file and run the PHP code in your editor. The debugger opens and runs the file in a Web browser, so you can see the changes made to the code file.

Related Searches:

References

Comments

You May Also Like

Related Ads

Featured