Login   Register  
PHP Classes
elePHPant
Icontem

File: person_class.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of piti  >  person  >  person_class.php  >  Download  
File: person_class.php
Role: ???
Content type: text/plain
Description: class person
Class: person
simple access file of object class
Author: By
Last change:
Date: 2002-05-09 06:14
Size: 2,891 bytes
 

Contents

Class file image Download
<?php
  /*
     FileName: person_class.php
	 Author: Piti Champeethong (Thailand)
	 Email: piti_fee@hotmail.com
	 Simple Access File Object With Class Person
	 created 09-05-2002
  */
  class Person {
	   /* define variables parameters*/
		var $name = ''; 
		var $surname = ''; 
		var $address = '';
		var $filename = '';
		var $ages = 0;

       /* constructor */
		function Person($name = '',$surname = '',$address= '',$ages = 0){
           $this->name = $name;
		   $this->surname = $surname;
		   $this->address = $address;
		   $this->ages = $ages;
		}

		/* method getName for display name */
		function getName(){
			return ($this->name);
		}

		/* method getSurname for display surname */
		function getSurname(){
			return ($this->surname);
		}

		/* method getAge for display age */
		function getAge(){
			return ($this->ages);
		}

		/* method getAddress for display address */
		function getAddress(){
			return ($this->address);
		}

		/* method setName for set value of name */
		function setName($name = ''){
			$this->name = $name;
		}

		/* method setSurname for set value of surname */
		function setSurname($surname = ''){
			$this->surname = $surname;
		}

		/* method setAge for set value of age */
        function setAge($age = 0){
			$this->ages = $age;
		}

		/* method setAddress for set value of address */
		function setAddress($address = ''){
			$this->address = $address;
		}

		/*
			method Init for clear value of class person
		*/

		function Init(){
			$this->name = '';
			$this->surname = '';
			$this->address = '';
			$this->ages = 0;
		}

        /*
			 method Save for save data into file 
		     option 1 is append file
			 option 0 is write new file
		*/
		function Save($filename = '',$object= NULL,$option=true){
			$op = ($option)? "a+" : "w";
            if(trim($filename) != ''){
				$fp = @fopen($filename,$op);
				if($fp == NULL) {
					return false;
				}else{
					fwrite($fp,serialize($object)."\n");
                    fclose($fp);
					unset($fp);
 				    return true;
				}
			}else{  return false; }
		}
		/* method dump show data */
		function Display($filename=''){
			$object = new Person();
			if(trim($filename) != ''){
	 			   $fp = @fopen($filename,"r");
				   if($fp == NULL) return false;
				   else{
                       while(! feof($fp)){
						   $object = unserialize(fgets($fp));
						   if($object != NULL){
	                            echo 'Name: ',$object->getName(),'<br>';
								echo 'Surname: ',$object->getSurname(),'<br>';
								echo 'Address: ',$object->getAddress(),'<br>';
								echo 'Age:',$object->getAge(),'<br>';
						   }
					   }
					   fclose($fp);
					   unset($object);
					   unset($fp);
		   			   return true;
				   }
			   }else return false;
		}

	}
?>