Forum Moderators: coopster
<?php
class user{
public $firstName;
public $familyName;
private $fullName;
public $gender;
public $age;
public $nationality;
/*** the constructor ***/
public function __construct(){
echo 'About this user: <br />';
}
/*** create the full name ***/
private function fullName() {
if (strlen($firstName) > 3 && strlen($familyName) > 3 ) {
$this->fullName = $firstName . ' ' . $familyName;
} else {
echo 'First or Family Name missing <br />';
}
}
public function constructUser() {
echo 'Name: '. $this->fullName . '<br />';
echo 'Gender: '. $this->gender . '<br />';
echo 'Age: '. $this->age . '<br />';
echo 'Nationality: '. $this->nationality . '<br />';
}
}
$user = new user;
$user->firstName = 'Thomas';
$user->familytName = 'Smith';
$user->gender = 'Male';
$user->age = 32;
$user->nationality = 'Austrian';
$user->constructUser();
?> About this user:
Name:
Gender: Male
Age: 32
Nationality: Austrian
[edited by: PartisanEntity at 6:43 pm (utc) on Feb 13, 2010]
class user{
public $firstName;
public $familyName;
private $fullName;
public $gender;
public $age;
public $nationality;
/*** the constructor ***/
public function __construct(){
echo 'About this user: <br />';
}
public function constructUser() {
if (strlen($this->firstName) > 3 && strlen($this->familyName) > 3) {
$this->fullName = $this->firstName . ' ' . $this->familyName;
}
echo 'Name: '. $this->fullName . '<br />';
echo 'Gender: '. $this->gender . '<br />';
echo 'Age: '. $this->age . '<br />';
echo 'Nationality: '. $this->nationality . '<br /><br />';
}
} public $firstName;
public $familyName;
private $fullName;
public $gender;
public $age;
public $nationality;