How To Call A method (function) From the Class in PHP Oops

Date Published: 08/04/2020 Published By: JaiSchool

You know that in object-oriented programming, we write all our code statements in a class. So here, you will know that if a class has a function in it then how to call it.

  • The first step is to create an object by class name. And make sure you added a 'new' keyword before. Store this object in a variable like that:- $result = new test();
  • Now, $result is an object, So to call function access it from $result object as a method like this : - $result->first(); See the example below.

class test{
	function first()
		echo "Function is called.";

$result = new test();


Note *** In object-oriented programming, variables inside a class called as property and functions are known as methods.

Also, read these articles

  1. how to split date & time in PHP
  2. Print timezone list
  3. date calculation
  4. Ch-1: beginner guide to SQL language
  5. How to create a database using SQL?
  6. How to delete a database?
  7. Why you are not able to delete the database?
  8. How to create a table in SQL?
  9. How to delete a table?
  10. How to insert data in a table?

Publish A Comment

Leave a Reply

Your email address will not be published.