A
A
Alexey Yarkov2015-11-10 18:21:44
PHP
Alexey Yarkov, 2015-11-10 18:21:44

Why is the function not being executed?

We have such a PHP script that gives javascript:

<?php
require_once($_SERVER['DOCUMENT_ROOT'] . "/core/config.php");
require_once(ABSPATH . "core/functions.php");

header("Content-type: application/javascript; charset=utf-8");

?>
<?php

// вот тут проблема.
// функция не выполняется
// нв выходе получаем строку is_auth = ;
// а должно быть true или false
echo "is_auth = ".is_auth().";\r\n";

?>
$(document).ready(function(){
  /*
  *	ОБРАБОТЧИКИ
  */
  // еще куча кода
  // кстати PHP константы нормально выводятся в контексте js

I believe it's because header("Content-type: application/javascript; charset=utf-8");
I'm right? What to do?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Osher, 2015-11-10
@yarkov

That's right. Look at the output of the command "echo false;" - empty line.

php > echo "is_auth = " . false . ";\r\n";
is_auth = ;
php > echo "is_auth = " . json_encode(false) . ";\r\n";
is_auth = false;

EDIT
php.net/manual/en/language.types.string.php#langua...
A boolean TRUE value is converted to the string "1". Boolean FALSE is converted to "" (the empty string). This allows conversion back and forth between boolean and string values.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question