gpt4 book ai didi

php - 调用未定义的 PHP 函数 : tried everything i can think of

转载 作者:行者123 更新时间:2023-11-29 10:24:58 25 4
gpt4 key购买 nike

我查看了所有通常存在问题的内容。也许我正在密切关注。谁能告诉是什么使“checkLocationExists”函数未定义?我已经检查了括号、';'s、包含、打开和关闭 php 标签(此处未显示关闭标签,它位于文件末尾。

<?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 因为这样看起来更具可读性。避免箭头前后的空格。

关于php - 调用未定义的 PHP 函数 : tried everything i can think of,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48483605/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com