@trofimovfedor

Почему переменная себя так странно ведет?

В файле core.php у меня класс Core с его методами и прочим.
core.php:
/**
 * the main class that is responsible for the main functions of the product
 */
class Core {
	private $config;
	private $hasInstalled;
	private $token;
	private $adminLogin;
	private $adminPassword;
	private $rconIP;
	private $rconPort;
	private $rconPassword;
	private $ip;
	private $port;
	private $unitpaySecretKey;
	private $theme;

	function __construct()
	{
		$config = file('data.config');
		$this->config = file_get_contents('data.config');
		$this->hasInstalled = $config[0];
		$this->token = $config[1];
		$this->adminLogin = $config[2];
		$this->adminPassword = $config[3];
		$this->rconIP = $config[4];
		$this->rconPort = $config[5];
		$this->rconPassword = $config[6];
		$this->ip = $config[7];
		$this->port = $config[8];
		$this->unitpaySecretKey = $config[9];
		$this->theme = $config[10];
	}

	function getConfig () {
		return $this->config; // returns an array
	}

	function hasInstalled () {
		return $this->hasInstalled; // returns a string
	}

	function getToken () {
		return $this->token; // returns a string
	}

	function getAdminLogin () {
		return $this->adminLogin; // returns a string
	}

	function getAdminPassword () {
		return $this->adminPassword; // returns a string
	}

	function getRconIP () {
		return $this->rconIP; // returns a string
	}

	function getRconPort () {
		return $this->rconPort; // returns a string
	}

	function getRconPassword () {
		return $this->rconPassword; // returns a string
	}

	function getIP () {
		return $this->ip; // returns a string
	}

	function getPort () {
		return $this->port; // returns a string
	}

	function getUnitpaySecretKey () {
		return $this->unitpaySecretKey; // returns a string
	}

	function getTheme () {
		return $this->theme; // returns a string
	}
}

$core = new Core();


Но, если я в файле setup.php подключу его с помощью require('core.php'); и выведу статус установки с помощью echo $core->hasInstalled();, то он как и должен выведет значение из файла data.config 1 строки. Но, если я сделаю условие
$hasInstalled = $core->hasInstalled();

if ($hasInstalled == "false") {
	echo "not installed";
}
if ($hasInstalled == "true") {
	echo "installed";
}
if ($hasInstalled != "true" && $hasInstalled != "false") {
	echo "wtf";
}
, то он вернет мне wtf. То есть не true и не false, но в тоже время если я вывожу без условия, то все верно работает. Это как?
  • Вопрос задан
  • 105 просмотров
Решения вопроса 1
dollar
@dollar
Делай добро и бросай его в воду.
Это не странно.
Просто по факту в переменной не "true" и не "false".
(это ответ на вопрос)

Попробуйте: echo($hasInstalled);
Также попробуйте: echo(strlen($hasInstalled));
(это отладка вашего кода)
Ответ написан
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы
YCLIENTS Москва
от 200 000 до 350 000 ₽
Ведисофт Екатеринбург
от 25 000 ₽
ИТЦ Аусферр Магнитогорск
от 100 000 до 160 000 ₽
22 апр. 2024, в 16:15
18000 руб./за проект
23 апр. 2024, в 16:55
10000 руб./за проект