| Viewed 88 times

PHP how to create an object


PHP how to create an object

PHP
1 Answer
Mohammad Qandeel
Answered
3

first of all, you must have a class.

the class definitions begin with the keyword class, followed by a class name

example 

<?php
class user
{
    // property declaration
    public $user ;

    // method declaration
    public function sayHello() {
        echo 'Hello';
    }
}
?>

after create a class you can instantiate a class

Example 

<?php
class user
{
    // property declaration
    public $user ;

    // method declaration
    public function sayHello() {
        echo 'Hello';
    }
}
$newUser = new user;
$newUser->sayHello();
?>

Output

Hello