当前位置:主页 > 软件编程 > PHP代码 >

PHP调用其他文件中的类

时间:2021-03-04 13:52:24 | 栏目:PHP代码 | 点击:

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

<?php
  class tool {

  function say(){
  $result="Hello,World";
  return $result;
  }

}

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

<?php
  require_once 'tool.php';
  $tool=new tool();
  $content=$tool->say();
  echo $content;
?>

您可能感兴趣的文章:

相关文章