lundi 6 août 2018

PHP's 'echo' does not work right

I need to check some return values of functions, which i put in a while loop:

    //should be true if an error comes up (a function returns false)
    $error = false;

    while ($error == false) {
        if (!$this->check_date()) {
            $this->log('bad date');
            $error = true;
            break;
        }

        if (!$this->check_location()) {
            $this->log('bad location');
            $error = true;
            break;
        }

        if (!$this->check_abc()) {
            $this->log('bad abc');
            $error = true;
            break;
        }

        //... more if's

        break;
    }

    //No error - great
    if ($error == false) {
        //Answer to my AJAX call
        echo "true";
    } else {
        $this->log('-There is an error-');
    }

So, whats the problem ?

I dont get an output to my AJAX call - it returns "" (no content), BUT if i put an echo "test"; here:

        //... more if's

        break;
    }

echo "test";

    //No error - great
    if ($error == false) {
        //Answer to my AJAX call
        echo "true";
    } else {
        $this->log('-There is an error-');
    }

i get the following back (multiple runs):

testtrue

testtrue

testtrue

testtrue

testtrue

So, whats the matter of this ?

Aucun commentaire:

Enregistrer un commentaire