Wednesday, August 17, 2011

OOPS with PHP

PHP oops:

**php class:

class is collection of variables and functions thats serves the common purpose. Class is user define datatypes.

Class has following members:

1. Attributes
2. Methods
exm:

class class_name
{
var $varibale = 'var_name';

function fn_name()
{
statement;
}
}

**Object:

To create Instance of class is a object.

Exm:
$object = new class_name();


y;
}

}

$a = new x();
$a = z();

?>
output : 10


**Inheritance:


Inheritance is the properties which one class share the data and methods of another class.

Inheritance is the process basing one class on another.

If you can write code once in its base class and reuse it derived class.

Base class provide methods, properties and other members to a derived class.



**Encapsulation:

The wrapping up of data and the methods into a single unit is called a encapsulation.

Encapsulation is a ability to hiding all the internal details of an object from outside only expose the data and method that are requiered.

Example:-cars and owners... all the functions of cars are encapsulated with the owners..

**Abstraction:

Show the neccessary details to the client of the object. The abstract class methods are must be implemented on derived class.

Example:-A simple example is using a base class "Animal", with a virtual function "Walk". In the case two-legged versus four-legged animals, both of them walk, but the actual mechanics are different. The "Walk" method abstracts the actual mechanics behind the walking that each "Animal" does. 2nd example:-A class called Animal. It has properties like ears,colour, eyes but they are not defined. It has methods like Running(), Eating(), etc. but the method does not have any body, just the definition.

**Interface:
Interface is a class that have many method and that method is only having declaration not having the implementation.
Interface has only a method declaration but no definition.

**Why we need interface

1. instead of multiple inheritance.(avoid multiple inheritance).
2. Use Inteface is common class for all other classes.
3. when you have two or more functionalities talking to each other that time we are going to interface.

**Single inheritance
One class inherited by only other one class.

**Multiple inheritance

One class inherited more than one class.

**Constructor
Constructor is a member fuction of the class, with name of the fuction is same as the class name.
The constructor is automatically invoke the instance of class(objects).

Answer2
class Point2D{
int x; int y;
public Point2D() : x(0) , y(0) {} //default (no argument) constructor
};

main(){

Point2D MyPoint; // Implicit Constructor call. In order to allocate memory on stack, the default constructor is implicitly called.

Point2D * pPoint = new Point2D(); // Explicit Constructor call. In order to allocate memory on HEAP we call the default constructor.
}

**Diff bw function and procedures

1. function can return values.
2. procedures can't return values.

**Polymorphism:
The ability to different objects to respond, to identical message its called polymorphism.
One name, multiple form.
One interface, multiple methods.

**PHP Polymorphism Function:
The PHP Polymorphism Method is one of the feature of OOP language. Generally we get polymorphism in two ways:
Compile time
Run time
Compile time polymorphism PHP is like function overloading, operator overloading etc. In Polymorphism function overloading we can create more than one function with same name but with different signature that means it could have different number of parameters, different datatype of the parameter etc. Depending on the actual number and/or the data type the compiler resolve the actual call .
In operator overloading predefined operators treat as functions and one object calls this function and passes another object as argument. PHP neither supports operator overloading nor function overloading.
Inheritance and virtual functions are the examples of PHP Run time polymorphism. PHP supports Inheritance as well as virtual function as function overriding.
Following examples will exemplify each of the types of polymorphism:
PHP Polymorphism Function Example:
";}}
class B extends A{
function Disp(){
echo "Inside the Chlid class
";}}
class C extends A{
}
$obj=new B();
$obj->Disp();
$obj2=new C();
$obj2->Disp();
?>

Output:
Inside the Chlid class
Inside the Base class



Difference bw web server and application server?
Webserver:

webserver serves the pages for viewing web browser using http protocal.
Webserver serves the static and dynamic pages using http protocal.
Webserver support only http protocal, And web application.

Application server:

Application server support all kind of protocals.
Application server handle business logic such as transaction and messaging.
Mysql 4 vs mysql5

main Reasons upgrading mysql 5:

1. stored procedure
2. trigger
3. Views

Enable subroutines :

To call to return values that you use another part of query.

Trigger:
More control the alteration made to a table.
Such as restrict access to specific data, perform logging and audit data modification.

Views:
Developers can use to show actual code directly from the screen of the client program this is used to debugging troubleshooting.

Why we are go innodb? Difference bw innodb and myisam?
Innodb:
1. innodb supports transaction.
2. Row-level locking.
3. foriegn key.
4. speed
5. data integirity(combination of differen table types in db)
6. Its Large data volumes.
7. innodb stores table and indexes in a table space.

Myisam:
1. Fast
2. Not supported foriegn key.
3. support small level data volumes
4. Each tables and indexes stored in seperate files.
5. Table level locking.

Row level locking vs table level locking?

Table level locking:

The data in one table modified by the other table. The entire table will locked for the next process.

Row-level locking:
Only the row of the table that is being updated is locked.

How to change default page in index.html other than index.php?

1. Change httpd.conf
2. DirectoryIndex index.php

or
(executed index.php if neither index.html and index.pl)
1. change .htaccess file
2. DirectoryIndex index.html index.pl /siva/index.php


Increase file size upload limit using php.ini or htaccess
Any php web application or server configured with default values set in php.ini and .htacess. Generally almost web hosting providers configures the web application to optimum settings, which effects server bandwidth, server memory limit, server disk space, and peak security measures. For file uploading and PHP script execution there is default configuration in PHP.ini. However almost hosting providers give chance to developer to customize this default configuration by override php.ini or. htaccess . some settings can be configured by ini_set() method at run time of script.
Default PHP.ini
;;;;;;;;;;;;;;;;
; File Uploads ;
;;;;;;;;;;;;;;;;

; Whether to allow HTTP file uploads.
file_uploads = On

; Temporary directory for HTTP uploaded files (will use system default if not
; specified).
upload_tmp_dir = "${path}\tmp\"

; Maximum allowed size for uploaded files.
upload_max_filesize = 2M

;;;;;;;;;;;;;;;;;;;
; Resource Limits;
;;;;;;;;;;;;;;;;;;;

max_execution_time = 30 ; Maximum execution time of each script, in seconds
max_input_time = 60 ; Maximum amount of time each script may spend parsing request data
;max_input_nesting_level = 64 ; Maximum input variable nesting level
memory_limit = 128M ; Maximum amount of memory a script may consume (128MB)
Increasing file upload size by php.ini
File upload size affected by mainly below PHP settings.
file_uploads = On
This setting must be on. It allows running uploads through HTTP.
Ensure this value is on the value can be On/Off or 1/0 or true/false.
upload_max_filesize = 20M
This value limits the size of uploaded single file. Give it value what ever your requirements.
post_max_size = 40M
This value limits the size of all the uploaded content. For example upload_max_filesize is for single file, if we upload 3 files simultaneously each 15mb total 45mb so it exceeds post_max_size.
Remember post_max_size must be larger about 40% of upload_max_filesize.
max_execution_time = 30
Generally image uploading and manipulating with GD or Imagemagic consumes much time. So it may exceeds 30 seconds. You can modify whatever your requirements. When a script execution time exceeded by this limit the server stops the scripts or gives fatal error.
memory_limit = 128M
Generally image uploading and manipulation with GD or Imagemagic consumes much server memory. When it exceeds this memory the server stops executing the script, then we see empty page or no response from server or we get a fatal error.
Completed example, to increase 10Mb
upload_max_filesize = 10M ;
post_max_size = 20M ;
memory_limit = 128M
Copy the above settings into your php.ini and put it in your web root directory.
Increasing file upload size by .htaccess
php_value upload_max_filesize 10M
php_value post_max_size 20M
php_value memory_limit 128M
Copy the above settings into your .htaccess file and put it in your web root directory.
Almost all web host providers give to override the .htacces ,so you can use above method.

No comments:

Post a Comment