What are the method in php?

Methods are used to perform actions.

In Object Oriented Programming in PHP, methods are functions inside classes. Their declaration and behavior are almost similar to normal functions, except their special uses inside the class.

Let's remind the role of a function.

  • First, we declare the function
  • Then we call it [Optionally we can send arguments into the function]
  • Some process is done inside the function
  • Then we return something from the function [Optional]

How to declare a method?

Let's declare a method inside a class named Example class to echo out a simple string that we give.


Chủ Đề