PHP调用其他文件中的类

首先在一个tool.php文件中声明一个类:

?

1

2

3

4

5

6

7

8

9

<?php

  class tool {

  function say(){

  $result="Hello,World";

  return $result;

  }

}

在另一文件main.php调用上面的类中的方法:

?

1

2

3

4

5

6

<?php

  require_once 'tool.php';

  $tool=new tool();

  $content=$tool->say();

  echo $content;

?>

转载https://www.jb51.net/article/137561.htm

猜你喜欢

转载自blog.csdn.net/weixin_42637737/article/details/83303774
今日推荐