I have an XML file with many member entries, formatted like so:
<staff>
    <member>
        <name></name>
        <image></image>
        <title></title>
        <email></email>
        <phone></phone>
        <location></location>
        <info></info>
        <webTitle></webTitle>
        <webURL></webURL>
    </member>
</staff>
setup
I've created 2 PHP classes, DisplayStaff and Employee.
- Employeecreates an Employee object, with private properties outlined in the XML above.
- DisplayStaffis a factory class. It loads the above XML file, iterates through it, creating an- Employeeinstance for each- <member>element in the XML. It stores the- Employeeobject in an array,- $Employees[].
On the page where I want to output the Employee information, I'd like to be able to reference it like so.
$Employees = new DisplayStaff();
$John = Employees['John'];
echo "Hello, my name is $John->name";
code
<?php
 class DisplayStaff
 {
    private var $staffList;
    private var $placeholderImg;
    private var $Employees; 
    public function __construct() {
        $staffList      = simplexml_load_file("../data/staff.xml");
        $placeholderImg = $staffList->placeholderImg;
        foreach ( $staffList->member as $member ) {
            $employee = formatEmployeeObj( $member );
            array_push( $Employees, $employee );
        }
        return $Employees;
     }
     private function formatEmployeeObj( $memberXML ) {
         $Employee = new Employee();
         $Employee->set( $name,      $memberXML->name );
         $Employee->set( $image,     $memberXML->image );
         $Employee->set( $title,     $memberXML->title );
         $Employee->set( $email,     $memberXML->email );
         $Employee->set( $phone,     $memberXML->phone );
         $Employee->set( $location,  $memberXML->location );
         $Employee->set( $info,      $memberXML->info );
         $Employee->set( $webTitle,  $memberXML->webTitle );
         $Employee->set( $webURL,    $memberXML->webURL );
         return $Employee;
     }
}
?>
<?php
class Employee
{
     private var $name     = "";
     private var $image    = "";
     private var $title    = "";
     private var $email    = "";
     private var $phone    = "";
     private var $location = "";
     private var $info     = "";
     private var $webTitle = "";
     private var $webURL   = "";
        public function get($propertyName) {
        if( property_exists($this, $propertyName) ) {
            return $this->$propertyName;
        }
            else{
                return null;
           }
    }
    public function set($propertyName, $propertyValue) {
        if( property_exists($this, $propertyName) ){
            $this->$propertyName = $propertyValue;
        }
    }
}
?>
problem
I can't seem to get this working. I'm new to working with classes. What do I need to change to have my classes behave how I desire them to?
Thank you in advanced for any help.
 
     
     
    