To create a class in PHP, you can use the class
keyword followed by the name of your class. Here's a simple example of a class named "Person":
main.php330 chars17 lines
This class has two properties (name and age), a constructor method, and one other method (sayHello). The constructor method is used to initialize the object's properties when it is instantiated.
To instantiate an object of this class, you would use the new
keyword, like this:
main.php34 chars2 lines
This creates a new instance of the Person class with the name "John" and age 30. You can then access the object's properties and methods like this:
main.php92 chars3 lines
gistlibby LogSnag