<?php
class Programmer {
// Class Properties
var $name; // Programmer's name
var $experience; // How long has been programming
var $lang; // Favorite Language
var $education; // Highest degree earned
// Class Constructor - function same name as the class
function Programmer($name, $experience, $lang, $education) {
$this->name=$name;
$this->experience=$experience;
$this->lang=$lang;
$this->education=$education;
}
// Getter/Setter functions for all properties in the class
function get_name() {
return $this->name;
}
function set_name($newname) {
$this->name = $newname;
}
function get_experience() {
return $this->experience;
}
function set_experience($newexperience) {
$this->experience = $newexperience;
}
function get_lang() {
return $this->lang;
}
function set_lang($newlang) {
$this->lang = $newlang;
}
function get_education() {
return $this->education;
}
function set_education($neweducation) {
$this->education = $neweducation;
}
// Utility data dump function
function output() {
echo "Programmer Name: ".$this->name."<br>";
echo $this->name." has ".$this->experience." years of programming experience.<br>";
echo $this->lang." is ".$this->name."'s favorite programming language.<br>";
echo $this->name." holds the degree: ".$this->education."<br><br>";
}
}
// Instantiating a programmer
$paul = new Programmer('Paul Conrad',12,'C++','Bachelor of Science in Computer Science');
$paul->output();
// Oops, Paul has programmed alot longer than 12 year, really is 22 years
$paul->set_experience(22);
$paul->output();
Programmer Name: <br> has years of programming experience.<br> is 's favorite programming language.<br> holds the degree: <br><br>Programmer Name: <br> has 22 years of programming experience.<br> is 's favorite programming language.<br> holds the degree: <br><br>
Output for 8.3.5
Warning: PHP Startup: Unable to load dynamic library 'sodium.so' (tried: /usr/lib/php/8.3.5/modules/sodium.so (libsodium.so.23: cannot open shared object file: No such file or directory), /usr/lib/php/8.3.5/modules/sodium.so.so (/usr/lib/php/8.3.5/modules/sodium.so.so: cannot open shared object file: No such file or directory)) in Unknown on line 0
Programmer Name: <br> has years of programming experience.<br> is 's favorite programming language.<br> holds the degree: <br><br>Programmer Name: <br> has 22 years of programming experience.<br> is 's favorite programming language.<br> holds the degree: <br><br>
Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; Programmer has a deprecated constructor in /in/ktHNZ on line 2
Programmer Name: Paul Conrad<br>Paul Conrad has 12 years of programming experience.<br>C++ is Paul Conrad's favorite programming language.<br>Paul Conrad holds the degree: Bachelor of Science in Computer Science<br><br>Programmer Name: Paul Conrad<br>Paul Conrad has 22 years of programming experience.<br>C++ is Paul Conrad's favorite programming language.<br>Paul Conrad holds the degree: Bachelor of Science in Computer Science<br><br>
Programmer Name: Paul Conrad<br>Paul Conrad has 12 years of programming experience.<br>C++ is Paul Conrad's favorite programming language.<br>Paul Conrad holds the degree: Bachelor of Science in Computer Science<br><br>Programmer Name: Paul Conrad<br>Paul Conrad has 22 years of programming experience.<br>C++ is Paul Conrad's favorite programming language.<br>Paul Conrad holds the degree: Bachelor of Science in Computer Science<br><br>