调用未定义的PHP函数:尝试了我能想到的一切

调用未定义的PHP函数:尝试了我能想到的一切,php,mysql,phpmyadmin,Php,Mysql,Phpmyadmin,我看了所有典型的问题。也许我正在密切关注。谁能告诉我是什么使得checkLocationExists函数未定义?我已经检查了括号“;”s、 includes、open和closing php标记closing one在这里不显示在文件末尾 <?php require_once 'DBOperations.php'; class Functions{ private $db; public function __construct() { $this -> db = new

我看了所有典型的问题。也许我正在密切关注。谁能告诉我是什么使得checkLocationExists函数未定义?我已经检查了括号“;”s、 includes、open和closing php标记closing one在这里不显示在文件末尾

<?php

require_once 'DBOperations.php';

class Functions{

private $db;

public function __construct() {
  $this -> db = new DBOperations();
}

public function searchPosts($rawLocation){
  $db = $this -> db;
  $locationArr = explode(",", $rawLocation);
  $formattedCity = $locationArr[0];
  $formattedState = $locationArr[1];
  echo 'String parameters for getLocationID are: 
'.$formattedCity.','.$formattedState.'.';
  if (checkLocationExists($formattedCity, $formattedState)){
      $locationID = $db -> getLocationID($formattedCity,
$formattedState);
      echo $locationID.'...is the locationId returned by "$db
>getLocationID()"';
      $response = $db -> getPostsByLocation($locationID);
      return json_encode($response);
  }else {
    $response['message'] = 'Location not in database, select one from
the AutoComplete drop down.';
    json_encode($response);
  }
}
public function checkLocationExists($city, $state) {
  $db = $this -> db;
  if ($db -> checkCity($city) && $db -> checkState($state) ) {
    return true;
  } else {
    return false;
    }
}

您应该修改代码以写入$this->checkLocationExists而不是checkLocationExists,因为您正在调用一个类函数

另外,请不要写$db->abcd,而是写$db->abcd,因为这样看起来更可读。。
避免在箭头前后出现空格。

从类内函数调用时,请尝试$this->checkLocationExists而不是checkLocationExists。无问题。。不客气。。如果这个答案解决了问题,那么就投票表决并点击复选标记