2. PHP is an open source , server-side scripting
language.
PHP is used to generate dynamic web pages.
Originally created by Rasmus Lerdorf in 1994,
the PHP reference implementation is now
produced by The PHP Group.PHP originally
stood for Personal Home Page , but it now
stands for Hypertext Preprocessor
3. PHP scripts reside between reserved PHP tags .
This php tags allows the programmer to embed
php scripts with in HTML pages.
4. Free
Multi OS Support(like linux,windows,OSX)
Easier to fix problem
Easy to understand
Speed
Object oriented
Compatible with many databases(SQL,MySQL)
Simple efficient
Secure flexible
familiar
5. PHP is also OOP language as it also
based on the concepts of object and
classes. PHP also uses the object
oriented concepts like encapsulation ,
inheritance , polymorphism , data
abstraction and constructors.
6. Class-: classes are the "blueprints“ for an
object and the actual code that defines the
properties and methods . and the class is
declared with in the tags.
Objects-: An object is an instance
of a class.
Any number of instances
of a class can be created.
<?php
class pen
{
}
?>
7. <?php
Class house
{
Public $name=“Soni”;
Public $age=47;
Function hello()
{
Echo “Hello world”;
}
$h=new house();
$g=new house();
Echo $h->name . “is” .$h->age .”year old”;
Echo $g->hello ()
?>
The output is-:soni is 47 year old hello world
8. Define:-Encapsulation is just wrapping of data in single
unit also we can say hiding the information of essential
details . Or we can say that it is the process of hiding the data
of the object from outside world and accessed to it is
restricted to members of the class.
Example:- Let You have a mobile phone…there it some
interface which help You to interact with cell phone and you
can uses the services of mobile phone. But the actually
working in cell phone is hide. You don’t know how it works
internally.
9. <?php
class App {
private static $_user;
public function User( ) {
if( $this->_user == null ) {
$this->_user = new User();
}
return $this->_user;
}
}
10. class User {
private $_name;
public function __construct() {
$this->_name = “Shivani";
}
public function GetName() {
return $this->_name;
}
}
$app = new App();
echo $app->User()->GetName();
?>
11. If a class name and function name will be
similar in that case function is known as
constructor. constructor is special type of
method because its name is similar to class
name . constructor automatically calls when
object will be initializing.
There are two types of constructor
1) user defined constructor
2) predefined constructor
12.
13. Note:-here we have called testA() method but
we didn’t call A() method because it
automatically called when object is initialized.
14. PHP introduce a new functionality to
define a constructor i.e __construct().
By using this function we can define a
constructor. it is known as predefined
constructor.
__construct() are also known as magic
function in PHP.
15.
16.
17. <?php
class BaseClass {
function __construct()
{
echo "Shivanin";
}
}
class SubClass extends BaseClass
{
function __construct()
{
parent::__construct();
echo “sonin";
}
}
$obj = new BaseClass();
$obj = new SubClass();
?>