Here is a trivial class with a method that should return the string that has been assigned to the property “question”. Why does it not print the returned property value from the method output?
I get no error messages, all I get is “Here is:” but the property’s value is missing 🙁
class DisplayQuestion {
public $question;
function __construct ($question){
$this->question = $question;
}
function output(){
echo "<p>Here is: $this->question</p>";
}
}
$test = new DisplayQuestion("What's your question?");
$test->output();
I run that code perfectly well on my machine, which means there is another issue (it’s not the code). Check your PHP logs as well as your HTTP server’s error and access logs, and (on your development server) enable display_errors in your ini file and see what’s going on.