我的 php 类有问题,我会将 return=true 或 false 从一个类的函数带到另一个类的另一个函数
<?php
class CheckCity {
private $x = 10;
private $y = 10;
public function __construct () {
$this->x = rand(10, 10);
$this->y = rand(10, 10);
}
public function Check() {
$exists = mysql_query("SELECT * FROM _users WHERE x = $this->x AND y = $this->y LIMIT 1");
if ( mysql_num_rows ( $exists ) == 1 ) {
return true;
} else {
return false;
}
}
}
class setCity extends CheckCity {
public function Set() {
parent::Check();
if ( $setcity->Check() == true ) {
echo "is TRUE";
} else {
echo "is FALSE";
}
}
}
这是索引:
<?php
$conn = mysql_connect('localhost', 'root', '') or die ('Error 1.');
mysql_select_db('db', $conn) or die ('Error 2.');
include "func.php";
$checkcity = new CheckCity();
$checkcity->Check();
$setcity = new setCity();
$setcity->Set();
所以这是错误:
Fatal error: Call to a member function Check() on a non-object in /func.php on line 37
我用谷歌搜索了错误,我尝试了很多解决方案,但无济于事。