MiX1.TK
Site menu
Login form
Section categories
Web Development [20]
Learn about PHP & Web Development
Education [4]
Learn for Free
Knowledge & Tricks [0]
General Knowledge,computer Knowledge & tricks
Writing World [2]
A MiX World of SmS on Various Topics
Search
Main » 2012 » November » 6 » PHP class usage
9:29 PM
PHP class usage

PHP classes

 <?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
 $jeet= new Programmer('jeetendra singh',1,'.NET/php'
 ,'Master of Computer Application');
 $jeet->output();
 
 $jeet->set_experience(22);
 $jeet->output();
 ?>
Category: Web Development | Views: 313 | Added by: admin-priyank | Rating: 5.0/1
Total comments: 0
Name *:
Email *:
Code *:
Calendar
«  November 2012  »
SuMoTuWeThFrSa
    123
45678910
11121314151617
18192021222324
252627282930
Entries archive
Our poll
Rate my site
Total of answers: 4
Site friends
  • Create a free website
  • Online Desktop
  • Free Online Games
  • Video Tutorials
  • All HTML Tags
  • Browser Kits
  • Statistics

    Total online: 1
    Guests: 1
    Users: 0
    Creative Commons License
    Free Downloads and Services by MiX1 is licensed under a Creative Commons Attribution-ShareAlike 3.0 Unported License
    Copyright MyCorp © 2024