0

I am trying to make a small survey form asking people questions and replying either yes or no.

I am trying though to execute the the first two functions on the 3rd function and also check if the answers were set but i get a:

Fatal error: Can't use method return value in write context in.

Can someone please help me or point me to the right path?

    <?php
class survey {

    ... some functions ...

    function check($rep1, $rep2){

        if (isset($this->q1($rep1)) && isset($this->q2($rep2))) {
            #######################    #######################
            echo "Thank you for the feedback";
        }elseif (! array_key_exists(@$_POST['answer'], $var)) {
            echo "Please select an option<br/>";
        }
    }
}
?>

The error is inside the check function on the first line.

1

1 Answer 1

4

Since functions always return something (even if it's NULL), using isset() on them is nonsensical.

isset is a language construct that takes a variable name and tells you if it exists.

In this case, why not just write if(isset($_POST['answer']))?

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you Kolink. You have been very helpful. The only thing is that I need to run the q1 and q2 functions only when the questions have been answered.. any ideas how this can be done? Thanks again for helping a newbie out..
@Kolink Shouldn't isset of a variable which exists but is set to null return false?
@Panki0: This is possible without errors in PHP 5.5. All you need to do is to upgrade to that PHP version. It's currently available in a alpha or beta release, so you can already test it today. php.net
@igorpan: yes. isset, basically checks for NULL not whether or not a variable is set.
I have fixed it it guys. Thank you all for trying to help out! I really appreciate it! Just thinking opposite/reverse actually made the script work. Thanks a lot again.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.