Я создаю объект Student с использованием ООП в PHP через API Graph Facebook.Моя проблема заключается в том, что не все пользователи совместно используют один и тот же объем данных на FB, поэтому, если конкретный пользователь не перечисляет определенные переменные, созданные в объекте, я получаю неопределенные сообщения о переменных.Как лучше всего подготовиться к этому, то есть создать объект, независимо от того, поделился ли пользователь всеми данными объекта или нет?Код ниже:
<?php
require_once('class.Student.php');
$name = $user_profile['name'];
$hometown = $user_profile['hometown']['name'];
$location = $user_profile['location']['name'];
$birthday = $user_profile['birthday'];
$highschool = $user_profile['education'][0]['school']['name'];
$hsgrad = $user_profile['education'][0]['year']['name'];
$collegeid = $user_profile['education'][1]['school']['id'];
$college = $user_profile['education'][1]['school']['name'];
$majorid = $user_profile['education'][1]['concentration'][0]['id'];
$major = $user_profile['education'][1]['concentration'][0]['name'];
$grad = $user_profile['education'][1]['year']['name'];
$company = $user_profile['work'][0]['employer']['name'];
$jobtitle = $user_profile['work'][0]['position']['name'];
$startdate = $user_profile['work'][0]['start_date'];
$interest = $interests['data'][0]['name'];
$interestid = $interests['data'][0]['id'];
$objStudent = new Student($name,$hometown,$location,$birthday,$highschool,$hsgrad,$collegeid,$college,$majorid,$major,$grad,$company,$jobtitle,$startdate,$interest,$interestid);
?>
И сам класс:
<?php
class Student {
public $name;
public $hometown;
public $location;
public $birthday;
public $highschool;
public $hsgrad;
public $collegeid;
public $college;
public $majorid;
public $major;
public $grad;
public $company;
public $jobtitle;
public $startdate;
public $interest;
public $interestid;
public function __construct($name,$hometown,$location,$birthday,$highschool,$hsgrad,$collegeid,$college,$majorid,$major,$grad,$company,$jobtitle,$startdate,$interest,$interestid) {
$this->name = $name;
$this->hometown = $hometown;
$this->location = $location;
$this->birthday = $birthday;
$this->highschool = $highschool;
$this->hsgrad = $hsgrad;
$this->collegeid = $collegeid;
$this->college = $college;
$this->majorid = $majorid;
$this->major = $major;
$this->grad = $grad;
$this->company = $company;
$this->jobtitle = $jobtitle;
$this->startdate = $startdate;
$this->interest = $interest;
$this->interestid = $interestid;
}
Я понимаю, как справиться с этим в функциях класса, используя простой isset, такой как:
function goalRecommender () {
if (isset($this->interest)) {
if ($this->interest =='Computer Science') {
echo "<p>Based on your interest in Computer Science, we recommend working in the software industry. Furthermore, your interest in user interface design would be thoroughly put to use at Facebook, one of the fastest growing technology companies in the world. If you would like to pursue another goal,
search our database to the right or click one of the 'popular goal' links.<p>";
}
elseif ($this->interests =='Finance') {
echo "<p>You're interested in Finance</p>";
}
elseif ($this->interests =='Film') {
echo "<p>You're interested in Film</p>";
}
elseif ($this->interests =='Marketing') {
echo "<p>You're interested in Marketing</p>";
} else {
echo "<p>Choose a goal.</p>";
}
} else {
echo "<p>What are you interested in?
<select>
<option>Finance</option>
<option>Marketing</option>
<option>Film</option>
<option>Software</option>
</select></p>";
}
}
Но я просто изучаю ООП в PHP и не знаю, как это сделать при создании объекта.Любое руководство будет с благодарностью.