PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
class MCQ
{
public $xml;
public $optionName;
public $questionStrap;
public $questiontype;
public $num_answers;
function __construct()
{
//This loads the xml file in....
$xml = simplexml_load_file("path");
$optionName = $xml->xpath("/question/options/answer/name");
$questionStrap = $xml->xpath("/question/strap");
$questiontype = $xml->xpath("/question/type");
$num_answers = count($xml->options->answer);
}
function __destruct()
{
}
public function generateMCQ()
{
echo $optionName[0];
}
}
?>
The echo works if it is within the construct but fails when it is outside.
<?php
class MCQ
{
public $xml;
public $optionName;
public $questionStrap;
public $questiontype;
public $num_answers;
function __construct()
{
//This loads the xml file in....
$this->xml = simplexml_load_file("path");
$this->optionName = $this->xml->xpath("/question/options/answer/name");
$this->questionStrap = $this->xml->xpath("/question/strap");
$this->questiontype = $this->xml->xpath("/question/type");
$this->num_answers = count($this->xml->options->answer);
}
function __destruct()
{
}
public function generateMCQ()
{
echo $this->optionName[0];
}
}
?>