Skip to content
Home » Blog » How to create class and function in PHP

How to create class and function in PHP

Creating class and function is PHP is the smart way to re use code. Here is the very simple example of class creation and function declaration.

You can create a file called class_base.php


//Declare Class
class Base
{

    function CheckUsers()
    {
        echo "Welcome to the function.";
       // Some more code

    }
}

How to access this function:

Create a file index.php


include_once 'class_base.php';
$user = new Base; //Initialize the class
$user->CheckUsers(); //Call the function

Will cover more advance topics in the next posts.

Leave a Reply

Your email address will not be published. Required fields are marked *