0 like 0 dislike
864 views
I am new to PHP5 and would like to learn some with basics in oops...
asked Apr 25, 2014 in Education & Reference by Neha (670 points) | 864 views
    

1 Answer

0 like 0 dislike
Class File
 
class person {
 
// explicitly adding class properties are optional - but is good practice
var $name;
 
function __construct($persons_name) {
 
$this->name = $persons_name;
}
 
 
public function get_name() {
 
return $this->name;
 
}
 
//protected methods and properties restrict access to those elements.
protected function set_name($new_name) {
 
if (name != "Jimmy Two Guns") {
$this->name = strtoupper($new_name);
}
 
}
 
 
 
// 'extends' is the keyword that enables inheritance
class employee extends person {
 
 
protected function set_name($new_name) {
 
if ($new_name == "Jackie Chain") {
$this->name = $new_name;
}
else if($new_name == "Daddy Yankie") {
parent::set_name($new_name);
}
 
}
 
function __construct($employee_name) {
 
$this->set_name($employee_name);
}
 
 
 
}
 
PHP Page
// Using our PHP objects in our PHP pages. 
 
 
$jackie = new person("Jackie Shroff");
 
 
echo "jackie's full name: " . $jackie->get_name();
 
$daddy = new employee("Daddy Yankie");
 
echo "---> " . $daddy->get_name();

 

answered Apr 25, 2014 by anonymous

Related questions

0 like 0 dislike
0 answers
0 like 0 dislike
1 answer
1 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
asked Sep 12, 2013 in Education & Reference by Sidh | 1,028 views
0 like 0 dislike
1 answer
1 like 0 dislike
1 answer
0 like 0 dislike
1 answer
asked Aug 1, 2017 in Education & Reference by Krish (880 points) | 44 views

Where your donation goes
Technology: We will utilize your donation for development, server maintenance and bandwidth management, etc for our site.

Employee and Projects: We have only 15 employees. They are involved in a wide sort of project works. Your valuable donation will definitely boost their work efficiency.

How can I earn points?
Awarded a Best Answer 10 points
Answer questions 10 points
Asking Question -20 points

Mathe Forum Schule und Studenten
1,169 questions
1,309 answers
276 comments
1,601 users