php method of calling class

angryTom
Release: 2023-02-28 10:30:01
Original
11009 people have browsed it

php method of calling class

php method of calling a class

In this article, I will share with you in detail how to call it in a PHP program Let’s learn the methods and code writing of another file class together.

First declare a class in a tool.php file:

<?php
  class tool {
  function say(){
  $result="Hello,World";
  return $result;
  }
}
Copy after login

Call the method in the above class in another file main.php:

<?php
  require_once &#39;tool.php&#39;;
  $tool=new tool();
  $content=$tool->say();
  echo $content;
?>
Copy after login

More PHP For relevant knowledge, please visit PHP中文网!

The above is the detailed content of php method of calling class. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
php
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template