marq

Dr. Charles Simonyi is the Father of Modern Microsoft Excel                                           JavaScript was originally developed by Brendan Eich of Netscape under the name Mocha, later LiveScript, and finally renamed to JavaScript.                                           The word "Biology" is firstly used by Lamarck and Treviranus                                           Hippocrates (460-370 bc) is known as father of medicine.                                           Galene, 130-200 is known as father of Experimental Physology                                           Aristotle (384-322 BC) is known as Father of Zoology because he wrote the construction and behavior of different animals in his book "Historia animalium"                                           Theophrastus(370-285 BC) is known as father of Botany because he wrote about 500 different plants in his book "Historia Plantarum".                                           John Resig is known as Father of Jquery -                                          HTML is a markup language which is use to design web pages. It was invented in 1990 by Tim Berners-Lee.                                                                The Google was founded by Larry Page and Sergey Brin.                                                                Rasmus Lerdorf was the original creator of PHP. It was first released in 1995.                                                               Facebook was founded by Mark Zuckerberg                                                               Bjarne Stroustrup, creator of C++.                                                                Dennis Ritchie creator of C                                                                                                                              James Gosling, also known as the "Father of Java"                                          At 11.44%, Bihar is India's fastest growing state                                          Father of HTML -Tim Berners Lee                                          orkut was created by Orkut Büyükkökten, a Turkish software engineer                    Photoshop: It came about after Thomas Knoll, a PhD student at the University of Michigan created a program to display grayscale images on a monochrome monitor which at the time was called 'Display'.

class


Everything OOP starts with classes. Classes are the type of objects, in the same way that integer may be the type of variable. You have to create the type before you can create specific objects of that type. That's important to realize -- a class is an object type. And before you can structure objects as you like, you can then create object of that class, as you are going to see.

class Person
{
.
.
.
}
===========================================
okay, that creates a class named Person. In PHP, classes are usually given names that start with a capital letter, and objects are given names that start with a lowercase letter. As you know, classes can hold data items, called properties, so let's give the person a name, $name. In the class, you're declaring the properties and methods that will go into  the objects of this class- and that means you use the var statement to declare properties in PHP. Here's how you add a property named &name to the Person class;

class Person
{

var $name;
.
.
}
================================================
we can add methods to Person class.

class Person
{
var $name;
function set_name($data)
{
.
.
}

}
=================================================

Now you've got to store the name passed to the set_name function in the $name variable. You  could do that, by accessing $name as a global variable;

class Person
{
var $name;
function set_name($data)
{
global $name;
.
}

}
======================================================

Then you can assign the argument  passed to set_name, $data to the internally stored name, $name, like this;


class Person
{
var $name;
function set_name($data)
{
global $name;
$name=$data;
.
}

}
=============================================================
That stores the person's name. You'll  also need some way to read the person's name, so you might add   another method called get_name;

class Person
{
var $name;
function set_name($data)
{
global $name;
$name=$data;
.
}
function get_name()
{
.
.
}

}
====================================================================
In this get method, you can access the internal name, $name, and return it like this .

class Person
{
  var $name;


   function set_name($data)
       {
          global $name;
          $name=$data;
.
        }
   function get_name()
      {
         global $name;
         return $name;
      }

==================================================================

that look goods, and it will work, but there's one change to make. You won't normally see OOP done using the global keyword. Instead, you usually refer to the properties tof the class using the $this keyword. The $this keyword points the current object. In PHP terms, this;

          global $name;
          $name=$data;
   can replace by this;

      $this->name=$data;

===================================================================

note the syntax here you use $this, followed by the -> operator. In addition, you omit the $ in front of the property you're referring to, like this; $this->name.


 class Person

{
  var $name;


   function set_name($data)
       {
          $this->name=$data;
.
        }
   function get_name()
      {
                 return $this->name;
      }

}

okay you've now created PHP Person class. Now it's time to put it to work, creating some objects.
==============================================================
Creating Objects

to create new object, you use the new operator in PHP. you just need to define your class and then you can use the new operator to create an object that class. Objects are stored as variables, so the object-creation process using new operator looks like this.


 class Person

{
  var $name;


   function set_name($data)
       {
          $this->name=$data;
.
        }
   function get_name()
      {
                 return $this->name;
      }

}


$raj=new Person;

Great, That's created a new person object named $ralph. Easy.
    All the methods and properties in the Person class are built into the $raj object. So how can you call the set_name method like this, using the -> operator again;


$raj=new Person;
$raj=set_name("Ramesh");



=======================================================================
example 1



<?php
class dog {
        var $name;
        var $age;
        var $owner;

        function dog($in_name="Rajesh",$in_age="1",$in_owner="Rajtutorial") {
                $this->name = $in_name;
                $this->age = $in_age;
                $this->owner = $in_owner;
                }

        function getage()
                {
                return ($this->age);
                }
        function getowner()
                {
                return ($this->owner);
                }
        function getname()
                {
                return ($this->name);
                }
}

$raj= new dog;
echo $raj->getage();
echo "<br>";
echo $raj->getname();
echo "<br>";
echo $raj->getowner();

?>
===========================================


Objects

The first thing that we need to wrap our heads around is the principle of Classes. Put simply, a Class is an Object, and an Object is a Class. But, like an everyday object, PHP Objects have certain properties, and they can do things. A simple class might look like this:


Example 2.
<?php
class human {
public $gender='Male';
}

$Johnny = new human;
echo 'Johnny is a '. $Johnny->gender.'.';
<?
================================================

<?php

class human {
public $gender;

public function __construct($gender)
{
$this->gender = $gender;

echo self::get_gender();
}

public function get_gender()
{
return $this->gender;
}
}

$Johnny = new human('male');
?>

===============================================

No comments:

Post a Comment