duangu6588 2014-05-20 06:16
浏览 25

访问类方法/函数PHP

I have an index.php and a Regions.php which is a class. I'm trying to call a method from Regions class to my index.php but it seems I can't access it.It says:

Call to undefined function getRegionInfo() in C:\xampp\htdocs\exercise4\index.php on line 7

But I already included the files I need. Here's the code.

index.php

$regions = new Regions;
$regions = getRegionInfo();
$regions = get_regions();

Here's my Region class

class Regions
{

 public function getRegionInfo()
 {
    $this->get_regions();
 }

 private function get_regions()
 {
    global $db;
    $result = array();
    $sql  = "SELECT RegionID, RegionName, IslandID FROM ref_regions";
    $stmt = $db->prepare($sql);
    $stmt->execute();
    $stmt->setFetchMode(PDO::FETCH_ASSOC);
    while ($row = $stmt->fetch()) 
    {
      array_push($result,array($row['RegionID'], $row['RegionName'], $row['IslandID']));
    }     
    return $result;
 }

}
  • 写回答

3条回答 默认 最新

  • doukuiqian5345 2014-05-20 06:19
    关注

    Class Methods are accessed by using the ->symbol. So use:

    $regions = new Regions();
    $regions->getRegionInfo();
    $regions->get_regions();
    

    And change your get_regions() from private to public, if you want to call it externally.

    评论

报告相同问题?

悬赏问题

  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度