Sunteți pe pagina 1din 26

1). What is the difference between the functions unlink() and unset()?

unlink is a function for file system handling. It will simply delete the file in context unset will set
UNSET the variable
2). why should we use Object oriented concepts in php ?
1. Object oriented PHP code is much more reusable because by its' very nature, it is modular. 2.
Object oriented PHP is easier to update. Again, because PHP code is organised into classes and
functions. 3. Object oriented PHP makes team programming much easier to manage. 4. Object
oriented PHP makes larger projects much easier to manage. 5. Object oriented PHP makes creating
code libraries much easier.
3). How many types of buffers does use MySQL?
global buffers and per-connection buffers
4). What is str_split function in php?
According to PHP official manual It is used to converts a string to an array. If the optional
split_length parameter is specified, the returned array will be broken down into chunks with each
being split_length in length, otherwise each chunk will be one character in length. FALSE is
returned if split_length is less than 1
5). Is it possible to pass data from JavaScript to PHP?
Yes, but not without sending another HTTP request.
6). How can we repair a MySQL table?
The syntex for repairing a mysql table is REPAIR TABLENAME, [TABLENAME, ], [Quick],[Extended]
This command will repair the table specified if the quick is given the mysql will do a repair of only
the index tree if the extended is given it will create index row by row
7). What is session hijacking?
Session hijacking, also known as TCP session hijacking, is a method of taking over a Web user
session by surreptitiously obtaining the session ID and masquerading as the authorized user. Once
the user's session ID has been accessed (through session prediction), the attacker can masquerade
as that user and do anything the user is authorized to do on the network. The session ID is
normally stored within a cookie or URL. For most communications, authenticationprocedures are
carried out at set up.
8). What is the difference between strstr() and stristr()?
strstr -- Find first occurrence of a string strstr() example <?php $email = 'user@example.com';
$domain = strstr($email, '@');echo $domain; // prints @example.com?> stristr -- Case-insensitive
strstr() stristr() example <?php $email = 'USER@EXAMPLE.com';echo stristr($email, 'e');//

outputs ER@EXAMPLE
9). which is faster mysql_unbuffered_query or mysql_query ?
when we do the select queries that retrieve large data sets from MySQL, mysql_unbuffered_query
in PHP is likely to give better performance than mysql_query. PHP manual says, it “sends a SQL
query to MySQL, without fetching and buffering the result rows automatically”.
10). List out some session functions in php?
session_save_path -- Get and/or set the current session save path session_is_registered -- Find
out whether a global variable is registered in a session session_unset -- Free all session variables
session_cache_expire -- Return current cache expire session_cache_limiter -- Get and/or set the
current cache limiter session_commit -- Alias of session_write_close() session_decode -- Decodes
session data from a string session_destroy -- Destroys all data registered to a session
11). what are the advantages of storing sessions in database?
If you store a session in a database you have several advantages: @ Improving the security
because on many hosting packages (shared host) PHP uses the same path for storing sessions for
all the users, somewhere that is not in your folders. @ You can track who is online etc. @ For
application that are running on multiple servers, you can store all the session data in one
database.
12). What is PHP?
PHP: Hypertext Preprocessor, an open source, server-side, HTML embedded scripting language
used to create dynamic Web pages. In an HTML document, PHP script (similar syntax to that of
Perl or C ) is enclosed within special PHP tags. Because PHP is embedded within tags, the author
can jump between HTML and PHP (similar to ASP and Cold Fusion) instead of having to rely on
heavy amounts of code to output HTML. And, because PHP is executed on the server, the client
cannot view the PHP code.
13). What is the maximum length for database, table & column names?
database- 64table -64columns-64alias-255
14). What is meant by Persistent Database Connections?
Persistent connections are links that do not close when the execution of your script ends. When a
persistent connection is requested, PHP checks if there's already an identical persistent connection
(that remained open from earlier) - and if it exists, it uses it. If it does not exist, it creates the link.
An 'identical' connection is a connection that was opened to the same host, with the same
username and the same password
15). difference between components and module
A Plugin will manipulate output already generated by the system. It typically does not run as a
stand-alone piece but takes data from other sources (i.e. the content) and manipulates it before
outputting to the user window. A plugin typically does not display directly to a user but does it's
work behind the scenes.
A module is typically considered to be an add-on to the site that extends the functionality of
another part of the system. It usually has fewer options that are configurable by the end user and
most of the time does not handle any storing of information into the database. A module usually
occupies a secondary portion of the web page and is not considered the primary focus of a page.
A component is the most extensive add-on. This typically adds completely new, or different,
functionality to your site and extends the overall site possibilities. A component handles data
manipulation as well as input and storage into the database. A component on most sites occupies
the main area of the website layout and is the primary focus of the page..
16). Creating a Component
For our basic component, we only require five files:
site/hello.php - this is the entry point to our component
site/controller.php - this file contains our base controller
site/views/hello/view.html.php - this file retrieves the necessary data and pushes it into the
template
site/views/hello/tmpl/default.php - this is the template for our output
hello.xml - this is an XML (manifest) file that tells Joomla! how to install our component.
17). Creating modules File Structure
There are four basic files that are used in the standard pattern of module development:
mod_helloworld.php - This file is the main entry point for the module. It will perform any
necessary initialization routines, call helper routines to collect any necessary data, and include the
template which will display the module output.
mod_helloworld.xml - This file contains information about the module. It defines the files that need
to be installed by the Joomla! installer and specifies configuration parameters for the module.
helper.php - This file contains the helper class which is used to do the actual work in retrieving the
information to be displayed in the module (usually from the database or some other source).
tmpl/default.php - This is the module template. This file will take the data collected by
mod_helloworld.php and generate the HTML to be displayed on the page
18). How can we submit a form without a submit button?
The main idea behind this is to use Java script submit() function in order to submit the form
without explicitly clicking any submit button. You can attach the document.formname.submit()
method to onclick, onchange events of different inputs and perform the form submission. You can
even built a timer function where you can automatically submit the form after xx seconds once the
loading is done (can be seen in online test sites).
19). In how many ways we can retrieve the data in the result set of MySQL using PHP?
You can do it by 4 Ways
1. mysql_fetch_row.
2. mysql_fetch_array
3. mysql_fetch_object
4. mysql_fetch_assoc
20). What is the difference between mysql_fetch_object and mysql_fetch_array?
mysql_fetch_object() is similar tomysql_fetch_array(), with one difference - an object is returned,
instead of an array. Indirectly, that means that you can only access the data by the field names,
and not by their offsets (numbers are illegal property names).
21). What are views in drupal
The Views module provides a customized, flexible method for Drupal site designers to control how
lists and tables of content (nodes in Views 1, almost anything in Views 2) are presented.This tool is
essentially a smart query builder that, given enough information, can build the proper query,
execute it, and display the results as a page, block, or other format such as an RSS feed.
22). What is cck in drupal
The Content Construction Kit allows you to add custom fields to custom content types using a web
interface
23). To add regions for Drupal 6.x
ADD the following code to you themename.info file:
regions[left] = Left sidebar
regions[right] = Right sidebar
regions[content] = Content
regions[header] = Header
regions[footer] = Footer
regions[newregion] = New Region
24). basic module in drupal needs.
test_module.info,test_module.install,test_module.module
25). What are the different tables present in MySQL
Total 5 types of tables we can create
1. MyISAM
2. Heap
3. Merge
4. INNO DB
5. ISAM
26). How can we encrypt the username and password using PHP?
The functions in this section perform encryption and decryption, and compression and
uncompression:
encryption decryption
AES_ENCRYT() AES_DECRYPT()
ENCODE() DECODE()
DES_ENCRYPT() DES_DECRYPT()
ENCRYPT() Not available
MD5() Not available
OLD_PASSWORD() Not available
PASSWORD() Not available
SHA() or SHA1() Not available
27). what is ob_start() does
Actually ob_start() tells PHP to start output buffering meaning that anything you output after
ob_start() wont be sent to the browser until the end of the page or ob_end() etc are reached.
So that means that once you use ob_start() and echo something out you can still set cookies
without any errors. For example:
<?php
ob_start();
echo "this will work";
setcookie("test", true);
ob_end_flush();
?>
28). What is "legacy mode" in joomla?
Legacy mode is a Plugin that can be activated by enabling the "System - Legacy" Plugin in the
Plugin Manager. This Plugin emulates Joomla! 1.0 and allows many version 1.0 extensions to run
on Joomla! 1.5. There is a minimal performance decrease by this, but in most cases it is not
significant.
29). When to use GET or POST
The HTML 2.0 specification says, in section Form Submission (and the HTML 4.0 specification
repeats this with minor stylistic changes. ): If the processing of a form is idempotent (i.e. it has no
lasting observable effect on the state of the world), then the form method should be GET. Many
database searches have no visible side-effects and make ideal applications of query forms. If the
service associated with the processing of a form has side effects (for example, modification of a
database or subscription to a service), the method should be POST.
30). Explain what is object oriented programming language?

Object oriented programming language allows concepts such as modularity, encapsulation,


polymorphism and inheritance. Objects are said to be the most important part of object oriented
language. Concept revolves around making simulation programs around an object. Organize a
program around its data (object)& set well define interface to that data. i.e. objects and a set of
well defined interfaces to that data. OOP is the common abbreviation for Object-Oriented
Programming. OOps have many properties such as DataHiding, Inheritence, Data Absraction, Data
Encapsulation and many more.
31). Explain about UML?
UML or unified modeling language is regarded to implement complete specifications and features of
object oriented language. Abstract design can be implemented in object oriented programming
languages. It lacks implementation of polymorphism on message arguments which is a OOPs
feature.
32). State some of the advantages of object oriented programming?
Some of the advantages of object oriented programming are as follows: -
a) A clear modular structure can be obtained which can be used as a prototype and it will not
reveal the mechanism behind the design. It does have a clear interface.
b) Ease of maintenance and modification to the existing objects can be done with ease.
c) A good framework is provided which facilitates in creating rich GUI applications.
33). Explain about inheritance in OOPS?
Objects in one class can acquire properties of the objects in other classes by way of inheritance.
Reusability which is a major factor is provided in object oriented programming which adds features
to a class without modifying it. New class can be obtained from a class which is already present.
34). Explain about a class in OOP?
In Object oriented programming usage of class often occurs. A class defines the characteristics of
an object and its behaviors. This defines the nature and functioning of a specified object to which it
is assigned. Code for a class should be encapsulated.
35). Explain the usage of encapsulation?
Encapsulation specifies the different classes which can use the members of an object. The main
goal of encapsulation is to provide an interface to clients which decrease the dependency on those
features and parts which are likely to change in future. This facilitates easy changes to the code
and features.
36). Explain what a method is?
A method will affect only a particular object to which it is specified. Methods are verbs meaning
they define actions which a particular object will perform. It also defines various other
characteristics of a particular object.
37). Explain about instance in object oriented programming?
Every class and an object have an instance. Instance of a particular object is created at runtime.
Values defined for a particular object define its State. Instance of an object explains the relation
ship between different elements.
38). Explain about inheritance?
Inheritance revolves around the concept of inheriting knowledge and class attributes from the
parent class. In general sense a sub class tries to acquire characteristics from a parent class and
they can also have their own characteristics. Inheritance forms an important concept in object
oriented programming.
39). Explain about abstraction?
Abstraction simplifies a complex problem to a simpler problem by specifying and modeling the
class to the relevant problem scenario. It simplifies the problem by giving the class its specific
class of inheritance. Composition also helps in solving the problem to an extent.
40). Explain the mechanism of composition?
Composition helps to simplify a complex problem into an easier problem. It makes different classes
and objects to interact with each other thus making the problem to be solved automatically. It
interacts with the problem by making different classes and objects to send a message to each
other.
41). what is session_set_save_handler in PHP? session_set_save_handler() sets the user-
level session storage functions which are used for storing and retrieving data associated with a
session. This is most useful when a storage method other than those supplied by PHP sessions is
preferred. i.e. Storing the session data in a local database.
42). what is garbage collection? default time ? refresh time? Garbage Collection is an
automated part of PHP , If the Garbage Collection process runs, it then analyzes any files in the
/tmp for any session files that have not been accessed in a certain amount of time and physically
deletes them. Garbage Collection process only runs in the default session save directory, which
is /tmp. If you opt to save your sessions in a different directory, the Garbage Collection process will
ignore it. the Garbage Collection process does not differentiate between which sessions belong to
whom when run. This is especially important note on shared web servers. If the process is run, it
deletes ALL files that have not been accessed in the directory.

There are 3 PHP.ini variables, which deal with the garbage collector: PHP ini value

name default

session.gc_maxlifetime 1440 seconds or 24 minutes

session.gc_probability 1

session.gc_divisor 100

43). PHP how to know user has read the email? Using Disposition-Notification-To: in mail
header we can get read receipt.
44). what is XML-RPC ? XML-RPC is a remote procedure call protocol which uses XML to encode
its calls and HTTP as a transport mechanism. An XML-RPC message is an HTTP-POST request. The
body of the request is in XML. A procedure executes on the server and the value it returns is also
formatted in XML.
45). default session time ? default session time in PHP is 1440 seconds or 24 minutes.

46). default session save path ? Default session save path id temporary folder /tmp

47). What is the difference between htmlentities() and htmlspecialchars()?

htmlspecialchars() – Convert some special characters to HTML entities (Only the most widely used)
htmlentities() – Convert ALL special characters to HTML entities

48). how to do session using DB?

bool session_set_save_handler ( callback $open , callback $close , callback $read , callback $write ,
callback $destroy , callback $gc ) using this function we can store sessions in DB.

49). 14) what is oops? encapsulation? abstract class? interface?

Object oriented programming language allows concepts such as modularity, encapsulation, polymorphism
and inheritance.

Encapsulation passes the message without revealing the exact functional details of the class. It allows
only the relevant information to the user without revealing the functional mechanism through which a
particular class had functioned.

Abstract class is a template class that contains such things as variable declarations and methods, but
cannot contain code for creating new instances. A class that contains one or more methods that are
declared but not implemented and defined as abstract. Abstract class: abstract classes are the class
where one or more methods are abstract but not necessarily all method has to be abstract. Abstract
methods are the methods, which are declare in its class but not define. The definition of those methods
must be in its extending class.

Interface: Interfaces are one type of class where all the methods are abstract. That means all the
methods only declared but not defined. All the methods must be define by its implemented class.

50). what are magic methods?

Magic methods are the members functions that is available to all the instance of class Magic methods
always starts with “__”. Eg. __construct All magic methods needs to be declared as public To use magic
method they should be defined within the class or program scope Various Magic Methods used in PHP 5
are: __construct() __destruct() __set() __get() __call() __toString() __sleep() __wakeup() __isset()
__unset() __autoload() __clone()

51). what is magic quotes? Magic Quotes is a process that automagically escapes incoming
data to the PHP script. It’s preferred to code with magic quotes off and to instead escape the data
at runtime, as needed.
52). types of error? how to set error settings at run time?

here are three basic types of runtime errors in PHP:

1. Notices: These are trivial, non-critical errors that PHP encounters while executing a script – for
example, accessing a variable that has not yet been defined. By default, such errors are not displayed to
the user at all – although you can change this default behaviour.

2. Warnings: These are more serious errors – for example, attempting to include() a file which does not
exist. By default, these errors are displayed to the user, but they do not result in script termination.

3. Fatal errors: These are critical errors – for example, instantiating an object of a non-existent class, or
calling a non-existent function. These errors cause the immediate termination of the script, and PHP?s
default behaviour is to display them to the user when they take place.

by using ini_set function.

53). what is cross site scripting? SQL injection?

Cross-site scripting (XSS) is a type of computer security vulnerability typically found in web applications
which allow code injection by malicious web users into the web pages viewed by other users. Examples of
such code include HTML code and client-side scripts.

SQL injection is a code injection technique that exploits a security vulnerability occurring in the database
layer of an application. The vulnerability is present when user input is either incorrectly filtered for string
literal escape characters embedded in SQL statements or user input is not strongly typed and thereby
unexpectedly executed

54). what is outerjoin? inner join?

OUTER JOIN in SQL allows us to retrieve all values in a certain table regardless of whether these values
are present in other tables

An inner join requires each record in the two joined tables to have a matching record. An inner join
essentially combines the records from two tables (A and B) based on a given join-predicate.
55). what is URL rewriting?

Using URL rewriting we can convert dynamic URl to static URL Static URLs are known to be better than
Dynamic URLs because of a number of reasons 1. Static URLs typically Rank better in Search Engines. 2.
Search Engines are known to index the content of dynamic pages a lot slower compared to static pages.
3. Static URLs are always more friendlier looking to the End Users. along with this we can use URL
rewriting in adding variables [cookies] to the URL to handle the sessions.

56). what is MVC? why its been used? Model-view-controller (MVC) is an architectural pattern
used in software engineering. Successful use of the pattern isolates business logic from user
interface considerations, resulting in an application where it is easier to modify either the visual
appearance of the application or the underlying business rules without affecting the other. In MVC,
the model represents the information (the data) of the application; the view corresponds to
elements of the user interface such as text, checkbox items, and so forth; and the controller
manages the communication of data and the business rules used to manipulate the data to and
from the model.

WHY ITS NEEDED IS 1 Modular separation of function 2 Easier to maintain 3 View-Controller separation
means:

A — Tweaking design (HTML) without altering code B — Web design staff can modify UI without
understanding code

57). what is CURL?

CURL means Client URL Library

curl is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, SCP,
SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE. curl supports SSL certificates, HTTP POST, HTTP PUT,
FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest,
NTLM, Negotiate, kerberos…), file transfer resume, proxy tunneling and a busload of other useful tricks.

CURL allows you to connect and communicate to many different types of servers with many different
types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap
protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading (this can also be
done with PHP’s ftp extension), HTTP form based upload, proxies, cookies, and user+password
authentication.

58). Drupal PROS over other cms


* Rock solid & high quality platform
* Real multi-site-feature (only one installation for several sites)
* Any Kind of user groups & user permissions, OpenId compliant in Version 6
* Can run membership and community sites, not only CMS etc
* Powerful templating system. Any XHTML or CSS template can be easily converted to Drupal.
* Drupal needs a little time investment to realize all the huge possibilities of Drupal
* Clear, high quality code and API (easy to integrate with other solutions etc)
* Flexibility and no known limitations
59). Joomla CONS over DRUPAL
* If you are not techy its good to start
* Easy install & setup with your mouse
* Easy learning curve
* Cannot integrate other scripts etc. to your site
* Generally you cannot create high-end sites, without investing huge amount
* No SEO out of the box, URLs are not search engine friendly.
* Server resources utilization is more compared to drupal
* Only one site per installation
* No Single Log-in to several sites
* No User groups & permissions
* More intuitive administration user interface
* Some polished modules for things like calendars, polls, etc.
* Modules cost you money

60). array_combine /array_merge— Creates an array by using one array for keys and

another for its values, array_merge — Merge one or more arrays

61). PHP Exception Handling

When an exception is thrown, the code following it will not be executed, and PHP will try to find the
matching "catch" block.If an exception is not caught, a fatal error will be issued with an "Uncaught
Exception" message.

<?php
//create function with an exception
function checkNum($number)
{
if($number>1)
{
throw new Exception("Value must be 1 or below");
}
return true;
}
//trigger exception
checkNum(2);
?>
The code above will get an error like this:
Fatal error: Uncaught exception 'Exception'
with message 'Value must be 1 or below' in C:\webfolder\test.php:6
Stack trace: #0 C:\webfolder\test.php(12):
checkNum(28) #1 {main} thrown in C:\webfolder\test.php on line 6

Try, throw and catch

To avoid the error from the example above, we need to create the proper code to handle an
exception.

Proper exception code should include:

1. Try - A function using an exception should be in a "try" block. If the exception does not trigger,
the code will continue as normal. However if the exception triggers, an exception is "thrown"
2. Throw - This is how you trigger an exception. Each "throw" must have at least one "catch"
3. Catch - A "catch" block retrieves an exception and creates an object containing the exception
information

<?php
//create function with an exception
function checkNum($number)
{
if($number>1)
{
throw new Exception("Value must be 1 or below");
}
return true;
}

//trigger exception in a "try" block


try
{
checkNum(2);
//If the exception is thrown, this text will not be shown
echo 'If you see this, the number is 1 or below';
}

//catch exception
catch(Exception $e)
{
echo 'Message: ' .$e->getMessage();
}
?>
62). Primary and Foreign key constraints are and what they are used for:
A primary key is a field or combination of fields that uniquely identify a record in a table, so that an
individual record can be located without confusion. The primary key fields cannot be null and cannot
contain duplicate data..A foreign key (sometimes called a referencing key) is a key used to link two
tables together. Typically you take the primary key field from one table and insert it into the other
table where it becomes a foreign key, A foreign key constraint specifies that the data in a foreign key
must match the data in the primary key of the linked table
63). Explain advantages of InnoDB over MyISAM? - Row-level locking, transactions, foreign key
constraints and crash recovery.
64). What is SERIAL data type in MySQL? - BIGINT NOT NULL PRIMARY KEY
AUTO_INCREMENT
65). What happens when the column is set to AUTO INCREMENT and you reach the
maximum value for that table? - It stops incrementing. It does not overflow to 0 to prevent
data losses, but further inserts are going to produce an error, since the key has been used
already.
66). Explain the difference between FLOAT, DOUBLE and REAL. - FLOATs store floating
point numbers with 8 place accuracy and take up 4 bytes. DOUBLEs store floating point
numbers with 16 place accuracy and take up 8 bytes. REAL is a synonym of FLOAT for now.
67). What is the query to get all tables from the selected database in MYSQL?

Show tables;
68). How to display nth highest record in a table for example? How to display 4th
highest (salary) record from customer table?
SELECT sal FROM `emp` order by sal desc limit (n-1),1If the question: "how to display 4th
highest (salary) record from customer table."The query will SELECT sal FROM `emp` order by
sal desc limit 3,1
69). What is the difference Delete and Drop ?
DELETE: ONCE WE DELETE ANY DATA FROM THE DATABASE WE CAN
EASILY RETURN BACK THE DATA BY USING ROLLBACK.DROP: ONCE WE Drop ANY DATA FROM THE
DATABASE WE CAN'T RETURN BACK THE DATA AND WE CAN SEE THE STRUCTURE OF OBJECT ONLY.
70). You wrote a search engine that should retrieve 10 results at a time, but at the
same time you’d like to know how many rows there’re total. How do you display that
to the user?
SELECT SQL_CALC_FOUND_ROWS page_title FROM web_pages LIMIT 1,10; SELECT
FOUND_ROWS(); The second query (not that COUNT() is never used) will tell you how many
results there’re total, so you can display a phrase "Found 13,450,600 results, displaying 1-10".
Note that FOUND_ROWS does not pay attention to the LIMITs you specified and always returns
the total number of rows affected by query.
71). What does this query mean: SELECT user_name, user_isp FROM users LEFT JOIN
isps USING (user_id) ?
It’s equivalent to saying SELECT user_name, user_isp FROM users LEFT JOIN isps WHERE
users.user_id=isps.user_id
72). What is Normalization?
Normalization is the process of efficiently organizing data in a database. There are two goals of
the normalization process: eliminating redundant data (for example, storing the same data in
more than one table) and ensuring data dependencies make sense (only storing related data
in a table). 1NF, 2NF, and 3NF along with the occasional 4NF. Fifth normal form are differnt
forms of it
First Normal Form (1NF)
First normal form (1NF) sets the very basic rules for an organized database: Eliminate
duplicative columns from the same table.
Create separate tables for each group of related data and identify each row with a unique
column or set of columns (the primary key).
Second Normal Form (2NF)
Second normal form (2NF) further addresses the concept of removing duplicative data: Meet
all the requirements of the first normal form.
Remove subsets of data that apply to multiple rows of a table and place them in separate
tables.
Create relationships between these new tables and their predecessors through the use of
foreign keys.
Third Normal Form (3NF)
Third normal form (3NF) goes one large step further: Meet all the requirements of the second
normal form.
Remove columns that are not dependent upon the primary key.
Fourth Normal Form (4NF)
Finally, fourth normal form (4NF) has one additional requirement: Meet all the requirements of
the third normal form.
A relation is in 4NF if it has no multi-valued dependencies..
73). feature difference in php4 and php5
Constructors (+1 for php5)
php4: Constructors are named after their class. If you change the name of a class, you
have to find all callers of the constructors.
php5: Constructors are named __construct. If no __construct method is found, falls back to
php4 behavior.
Destructors (+1 for php5)
php4: No such concept.
php5: Destructors are named __destruct.
$this = new Class(...); (+2 for php4)
php4: $this can be reassigned, allowing one to change the class implementing an object. A
very useful feature and one I used quite a lot.
php5: Assignment to $this is explicitly forbidden. Factory methods are the recommended
substitute.
Public, Protected, Private Class Variables (no point)
php4: All class variables are public.
php5: Class variables can have differing access levels.
Class Constants (+0.5 for php5)
php4: No such thing.
php5: Has them as Class::CONSTANT.
Autoloading (+1 for php5)
php4: No such thing. If you want to load classes, you'd better make sure there are
require_once statements all over the place. Or write an object-creation function
(make_instance) which automatically loads any class that doesn't exist.
make_instance('Class', ...) isn't nearly as pretty as new Class(...), though.
php5: Autoloading exists, provided you write an __autoload function. No more does
require_once need to be littered around one's code. A marginal savings overall, but still an
improvement.

73). the features in PHP 5 are the inclusions(OOPS Concept)

visibility, abstract and final classes and methods, additional magic methods, interfaces, cloning

and typehinting.
a class can only inherit from one base class. It is not possible to extend multiple classes. It is
possible to access the overridden methods or static properties by referencing them with

parent::.
Class member variables are called "properties".
Within class methods the properties, constants, and methods may be accessed by using the
form $this->property (where property is the name of the property) unless the access is to a
static property within the context of a static class method, in which case it is accessed using
the form self::$property.

Many developers writing object-oriented applications create one PHP source file per-class
definition. One of the biggest annoyances is having to write a long list of needed includes at
the beginning of each script (one for each class). In PHP 5, this is no longer necessary. You
may define an __autoload function which is automatically called in case you are trying to use a
class/interface which hasn't been defined yet. By calling this function the scripting engine is
given a last chance to load the class before PHP fails with an error.

Parent constructors are not called implicitly if the child class defines a constructor. In order to
run a parent constructor, a call to parent::__construct() within the child constructor is
required.
PHP 5 introduces a destructor concept. The destructor method will be called as soon as all
references to a particular object are removed or when the object is explicitly destroyed or in
any order in shutdown sequence. Like constructors, parent destructors will not be called
implicitly by the engine. In order to run a parent destructor, one would have to explicitly call
parent::__destruct() in the destructor body. The destructor will be called even if script

execution is stopped using exit(). Calling exit() in a destructor will prevent the remaining
shutdown routines from executing.

The visibility of a property or method can be defined by prefixing the declaration with the
keywords public, protected or private. Class members declared public can be accessed
everywhere. Members declared protected can be accessed only within the class itself and
by inherited and parent classes. Members declared as private may only be accessed by the
class that defines the member. Same applies for visibility of member functions.

when you extend a class, the subclass inherits all of the public and protected methods from
the parent class. Unless a class overrides those methods, they will retain their original
functionality.
The Scope Resolution Operator (also called Paamayim Nekudotayim) or in simpler terms, the

double colon, is a token that allows access to static, constant, and overridden properties or
methods of a class. When referencing these items from outside the class definition, use the
name of the class. Two special keywords self and parent are used to access properties or
methods from inside the class definition. When an extending class overrides the parents
definition of a method, PHP will not call the parent's method. It's up to the extended class on
whether or not the parent's method is called. Declaring class properties or methods as static
makes them accessible without needing an instantiation of the class. A property declared as
static can not be accessed with an instantiated class object (though a static method can).
static methods are callable without an instance of the object created. Static properties cannot
be accessed through the object using the arrow operator ->. Common usage of static
members is in the Singleton pattern

PHP 5 introduces abstract classes and methods. It is not allowed to create an instance of a
class that has been defined as abstract, but it can be inheritted. Any class that contains at
least one abstract method must also be abstract. Methods defined as abstract simply declare
the method's signature they cannot define the implementation. When inheriting from an
abstract class, all methods marked abstract in the parent's class declaration must be defined
by the child; additionally, these methods must be defined with the same (or a less restricted)
visibility. For example, if the abstract method is defined as protected, the function
implementation must be defined as either protected or public, but not private.
Object interfaces allow you to create code which specifies which methods a class must
implement, without having to define how these methods are handled. Interfaces are defined
using the interface keyword, in the same way as a standard class, but without any of the
methods having their contents defined. All methods declared in an interface must be public. To
implement an interface, the implements operator is used. All methods in the interface must be
implemented within a class; failure to do so will result in a fatal error. Classes may implement
more than one interface if desired by separating each interface with a comma. Its possible for
interfaces to have constants. Interface constants works exactly like class constants except
they cannot be overridden by a class/interface that inherits it. Interface supports mulitple
inherittance.

Overloading in PHP provides means to dynamically "create" properties and methods. The
overloading methods are invoked when interacting with properties or methods that have not
been declared or are not visible in the current scope. All overloading methods must be defined
as public.

PHP 5 provides a way for objects to be defined so it is possible to iterate through a list of
items, with, for example a foreach statement. By default, all visible properties will be used for
the iteration.

Patterns are ways to describe best practices and good designs. They show a flexible solution to
common programming problems. The Factory pattern allows for the instantiation of objects at
runtime. It is called a Factory Pattern since it is responsible for "manufacturing" an object. A
Parameterized Factory receives the name of the class to instantiate as argument. The
Singleton pattern applies to situations in which there needs to be a single instance of a class.
The most common example of this is a database connection. Implementing this pattern allows
a programmer to make this single instance easily accessible by many other objects. Common
usage of static members is in the Singleton pattern

The function names __construct, __destruct, __call, __callStatic, __get, __set, __isset,
__unset, __sleep, __wakeup, __toString, __invoke, __set_state and __clone are magical in
PHP classes. You cannot have functions with these names in any of your classes unless you
want the magic functionality associated with them. Magic method are so called , since it is
executed by default.

use of __sleep is to commit pending data or perform similar cleanup tasks.


use of __wakeup is to reestablish any database connections that may have been lost during
serialization and perform other reinitialization tasks.
The __toString method allows a class to decide how it will react when it is converted to a
string.
The __invoke method is called when a script tries to call an object as a function.

PHP 5 introduces the final keyword, which prevents child classes from overriding a method by
prefixing the definition with final. If the class itself is being defined final then it cannot be
extended. Properties cannot be declared final, only classes and methods may be declared as
final.

An object copy is created by using the clone keyword (which calls the object's __clone()
method if possible). An object's __clone() method cannot be called directly.

when using the identity operator (===) to compare objects, object variables are identical if
and only if they refer to the same instance of the same class.

Type Hinting. Functions are now able to force parameters to be objects (by specifying the
name of the class in the function prototype) or arrays

References
References in PHP are a means to access the same variable content by different names.
There are three basic operations performed using references: assigning by reference, passing
by reference, and returning by reference.

assigning by reference: PHP references allow you to make two variables refer to the same
content.
Eg: $a= & $b;
pass by reference : This is done by making a local variable in a function and a variable in the
calling scope referencing the same content
<?php
function foo(&$var){ $var++; }
$a=5;
foo($a);
?>
You can pass a variable by reference to a function so the function can modify the variable.
The following things can be passed by reference: Variables, i.e. foo($a), New statements, i.e.
foo(new foobar()) , References returned from functions
Returning by reference is useful when you want to use a function to find to which variable a
reference should be bound.

Predefined variables in php


$GLOBALS — References all variables available in global scope
$_SERVER — Server and execution environment information
$_GET — HTTP GET variables
$_POST — HTTP POST variables
$_FILES — HTTP File Upload variables
$_REQUEST — HTTP Request variables
$_SESSION — Session variables
$_ENV — Environment variables
$_COOKIE — HTTP Cookies
$php_errormsg — s a variable containing the text of the last error message generated by PHP
$HTTP_RAW_POST_DATA — Raw POST data
$http_response_header — HTTP response headers
$argc — The number of arguments passed to script
$argv — Array of arguments passed to script

Session support in PHP consists of a way to preserve certain data across subsequent accesses.
A visitor accessing your web site is assigned a unique id, the so-called session id. This is either
stored in a cookie on the user side or is propagated in the URL. By default, all data related to a
particular session will be stored in a file in the directory specified by the session.save_path INI
option. A file for each session (regardless of if any data is associated with that session) will be
created. SID ( string )
Constant containing either the session name and session ID in the form of "name=ID"

Memcached : Free & open source, high-performance, distributed memory object caching
system, generic in nature, but intended for use in speeding up dynamic web applications by
alleviating database load.

File Uploads
$ php.ini directive for file uploads---
file_uploads---yes /no for file uploads
upload_tmp_dir---specify temporary directory for file uploads
upload_max_filesize-----max file upload size
max_file_uploads-----max no of file uploaded simultaneously
enc type of form during file upload: enctype="multipart/form-data"

The global $_FILES : arrays will contain all the uploaded file information.
If input type of the file upload name userfile then the array has
$_FILES['userfile']['name'] : The original name of the file on the client machine.
$_FILES['userfile']['type']: The mime type of the file
$_FILES['userfile']['size']: The size, in bytes, of the uploaded file.
$_FILES['userfile']['tmp_name']: The temporary filename of the file in which the uploaded file
was stored on the server.
$_FILES['userfile']['error']: The error code associated with this file upload.

Function relating file upload


is_uploaded_file — Tells whether the file was uploaded via HTTP POST, Returns TRUE if the file
named by filename was uploaded via HTTP POST.
move_uploaded_file — Moves an uploaded file to a new location. This function checks to
ensure that the file designated by filename is a valid upload file (meaning that it was uploaded
via PHP's HTTP POST upload mechanism). If the file is valid, it will be moved to the filename
given by destination.

file_get_contents() returns the file in a string , starting at the specified offset up to maxlen
bytes. On failure, file_get_contents() will return FALSE.
file — Reads entire file into an array

webservice: A "web service" is a network accessible interface to application functionality


built using XML and usually HTTP. These interfaces work regardless of the client's and server's
platform and language.
Basic steps
1. Web Services client script builds up the request

2. Client sends the request to server using HTTP

3. Server replies and returns an XML document with results

4. Client parses XML

3 forms of webservices

1). SOAP:Simple Object Access Protocol, A few PHP implementations: PEAR::SOAP, PHP-
SOAP, NuSOAP

2). REST: REpresentational State Transfer

3). XML RPC: XML Remote Procedure Call-- Make URI request using existing HTTP
methods: GET / POST / PUT / DELETE ----Data returned as XML, so we need to parse XML

CSS: Cascading Style Sheets

Elements: Elements are the basis of CSS display. In HTML, the most common elements are easily
recognizable, such as p, table, span, a, and div.

Replaced elements ---image , input etc

Non replaced elements: Div , span, p tags


Block-level elements: it generates "breaks" before and after the element box eg- p and div

Inline level elements: generate an element box within a line of text and do not break up the flow of
that line. Eg: a tag

Link tag: CSS uses it to link style sheets to the document. link must be placed inside the head
element of html

Attribute of link tag:

Media: allowed values for this attribute

all--Use in all presentational media.

aural-- Use in speech synthesizers, screen readers, and other audio renderings of the document.

braille--Use when rendering the document with a Braille device.

embossed--Use when printing with a Braille printing device.

handheld--Use on handheld devices like personal digital assistants or web-enabled cell phones.

print--Use when printing the document for sighted users and also when displaying a "print
preview" of the document.

projection--Use in a projection medium, such as a digital projector used to present a slideshow


when delivering a speech.

screen--Use when presenting the document in a screen medium like a desktop computer monitor.
All web browsers running on such systems are screen-medium user agents.

tty--Use when delivering the document in a fixed-pitch environment like teletype printers.

tv--Use when the document is being presented on a television.

<style > tag , @import are 2 other method to write css

@import url(‘sheet2.css’); Navigator 4.x and Opera 3.x both ignore @import outright so can
actually be used to one's advantage in "hiding" styles from these browsers. @import can be highly
useful if you have an external style sheet that needs to use the styles found in other external style
sheets. Since external style sheets cannot contain any document markup,

Alternate style sheets. are defined by making the value of the rel attribute alternate stylesheet and
are used in document presentation only if they are selected by the user. Alternate style sheets are
supported in most Gecko-based browsers like Mozilla and Netscape 6+, and in Opera 7. They can
be supported in Internet Explorer through the use of JavaScript but are not natively supported by
those browsers.

inline style : style attributes in html fields

CSS allows you to create rules that are simple to change, edit, and apply to all the text elements
you define . h2 {color: gray;} changes color of all h2’s to grey
Each rule has two fundamental parts, the selector and the declaration block.

The declaration block is composed of one or more declarations. eg: color:gray; Each declaration is

a combination of a CSS property and a value of that property. A declaration is always formatted as a 


property followed by a colon and then a value followed by a semicolon. The colon and semicolon can be 
followed by zero or more spaces.

The selector, shown on the left side of the rule, defines which piece of the document will be
affected.—here in above ex it is h1, A selector is most often an HTML element.

Grouping ­­­ eg :  body, table, th, td, h1, h2, h3, h4, p, pre, strong, em, b, i {color: gray;}

universal selector:  CSS2 introduced a new simple selector called the universal selector, displayed as an 
asterisk (*). This selector matches any element at all eg­­ : * {color: red;} ­­The universal selector lets 
you assign the color value red to every element in the document.  

class selectors­­­­ uses class attribute of html element ­­ In order to associate the styles of a class selector 
with an element, you must assign a class attribute to the appropriate value. In the previous code, a class 
value of warning was assigned to two elements. Eg­­ .warning {font­weight: bold;}

Multiple Classes­­­it's possible to have a space­separated list of words in a single class value. Eg­­­ <p 
class="urgent warning"> where style is   .warning {font­weight: bold;} .urgent {font­style: italic;}

ID selectors------ID selectors are preceded by an octothorpe (#)­also known as a pound sign, hash mark

Eg----#first­para {font­weight: bold;}  this rule applies to html elemnt in the document having attribute 

ID as first­para eg­­­ <p id="lead­para">

Deciding Between Class and ID ­­­­  1). You may assign classes to any number of elements­ IDs, on the 
other hand, are used once, and only once, within an HTML document. 2). class selectors can be 
combined­ ID selectors can't be combined, since ID attributes do not permit a space­separated list of 
words. 3).  difference between class and id names is that IDs carry a heavier weight when trying to 
determine which styles should be applied to a given element.

Attribute Selectors­­­ CSS2 introduced attribute selectors, which can be used to select elements based 
on their attributes and the values of those attributes. four types of attribute selectors.

a. Simple Attribute Selection­­­­­ If you want to select elements that have a certain attribute, regardless 
of the attribute's value, you can use a simple attribute selector. Eg: h1[class] {color: silver;}

b. Selection Based on Exact Attribute Value­­­­eg: a[href="http://www.css­discuss.org/about.html"] 
{font­weight: bold;}
c. Selection Based on Partial Attribute Values – eg : p[class~="warning"] {font­weight: bold;} this 
works for <p class="urgent warning">

d. A Particular Attribute Selection Type­­­ eg: *[lang|="en"] {color: white;}  This rule will select any 
element whose lang attribute is equal to en or begins with en­.

the power of CSS is based on the parent­child relationship of elements. HTML documents are based on 
a hierarchy of elements, which is visible in the "tree" view of the document. Every element in the 
document is either the parent or the child of another element, and it's often both. 

descendant selectors (contextual selectors) ­­ descendant selectors is the act of creating rules that operate 
in certain structural circumstances but not others. Eg: h1 em {color: gray;}­­ This rule will make gray 
any text in an em element­that is, the descendant of an h1 element.

Pseudo­class selectors and Pseudo­element selectors. ­­­­ These selectors let you assign styles to 
structures that don't necessarily exist in the document, or to phantom classes that are inferred by the state 
of certain elements, or even by the state of the document itself.

So a:visted ,a:link is psuedo classes and the stae of a is called psuedo elements.

Link pseudo­classes : eg a {color: blue;} a:visited {color: red;}  a:link {color: red;}

Dynamic pseudo­classes:   a:focus, a:hover, a:active s in case for a tag

Styling the first letter: first pseudo­element styles the first letter, and only that letter, of a block­level 
element: eg: p:first­letter {color: red;}

Styling the first line: :first­line can be used to affect the first line of text in an element. Eg: p:first­line 
{color: purple;}

In CSS2, the :first­letter and :first­line pseudo­elements can be applied only to block­level elements such 
as headings or paragraphs

Specificity :   h1 {color: red;} body h1 {color: green;} ­­ For every rule, the user agent evaluates the 
specificity of the selector and attaches it to each declaration in the rule. When an element has two or 
more conflicting property declarations, the one with the highest specificity will win out. A selector's 
specificity is determined by the components of the selector itself. A specificity value is expressed in four 
parts, like this: 0,0,0,0 . 

a. For every ID attribute value given in the selector, add 0,1,0,0.  

b. For every class attribute value, attribute selection, or pseudo­class given in the selection, add 0,0,1,0. 
c. For every element and pseudo­element given in the selector, add 0,0,0,1. CSS2 contradicted itself as to 
whether pseudo­elements had any specificity at all, but CSS2.1 makes it clear that they do, and this is 
where they belong. 

d. Combinators and the universal selector do not contribute anything to the specificity .

Importance­­­­a rule is so important that it outweighs all other considerations. CSS2.1 calls these 
important rules, mark them by inserting the phrase !important just before the terminating semicolon in a 
rule eg:  p.dark {color: #333 !important; background: white !important;}

Inheritance­­­­­­Inheritance is the mechanism by which styles are applied not only to a specified 
element, but also to its descendants.  Eg: If a color is applied to an h1 element, for example, then that 
color is applied to all text in the h1, even the text enclosed within child elements of that h1:

Cascade: the process by which conflicting declarations are sorted out and from which the final
document presentation is determined. Rules are:

a. Find all declarations that contain a selector that matches a given element.

b. Sort by explicit weight all declarations applying to the element.

c. Sort by specificity all declarations applying to a given element.

d. Sort by order all declarations applying to a given element.

It is important to remember that font, being a shorthand property, can act in unexpected ways if
you are careless with its use. When the shorthand property font is used, any omitted values are
reset to their defaults.

CSS assumes that every element generates one or more rectangular boxes, called element boxes.
Each element box has a content area at its core. The content area is surrounded by optional
amounts of padding, borders, and margins. Each of the margins, borders, and padding can be set
using various properties.

The complete box model


We can set Negative margins to margin values

Positioning---- It allows you to define exactly where element boxes will appear relative to where
they would ordinarily be-or relative to a parent element, or another element, or even to the
browser window itself. Static, relative, absolute, fixed are 4 positioning available

Floating---property utililizing style attribute float;

Clearance is extra spacing added above an element's top margin in order to push it past any
floated elements.

Overflow : an element that has been pinned to a specific size, and the content doesn't fit. You can
take control of the situation with the overflow property.

Content clipping: In situations where the content of an absolutely positioned element overflows its
element box, and overflow has been set such that the content should be clipped, it is possible to
alter the shape of the clipping region by using the property clip.

Z-index: With all of the positioning going on, there will inevitably be a situation where two
elements will try to exist in the same place, visually speaking. Obviously, one of them will have to
overlap the other-but how does one control which element comes out "on top". z-index lets you
alter the way in which elements overlap each other. It takes its name from the coordinate system
in which side-to-side is the x-axis and top-to-bottom is the y-axis.

Fixed positioning: fixed positioning is just like absolute positioning, except the containing block of a
fixed element is the viewport. Eg: to create frame-style interfaces using fixed positioning.

Relative positioning: a positioned element is shifted by use of the offset properties. Eg : to shift an
image up and to the left

Css sprites : CSS sprites are a way to reduce the number of HTTP requests made for image
resources referenced by your site. Images are combined into one larger image at defined X and Y
coorindates. Having assigned this generated image to relevant page elements the background-
position CSS property can then be used to shift the visible area to the required component image.

MySQL, the most popular Open Source SQL database management system, is developed,
distributed, and supported by Sun Microsystems, Inc. MySQL is a database management system.
MySQL is a relational database management system. MySQL software is Open Source. The MySQL
Database Server is very fast, reliable, and easy to use. MySQL Server works in client/server or
embedded systems. A large amount of contributed MySQL software is available.

New in MySQL 5.0

BIT Data Type, Cursors, Information Schema, Instance Manager, stored procedures and stored
functions, Triggers,Views, VARCHAR Data Type

Indexes are used to find rows with specific column values quickly.

To find the rows matching a WHERE clause quickly.

To eliminate rows from consideration. If there is a choice between multiple indexes, MySQL
normally uses the index that finds the smallest number of rows.

To retrieve rows from other tables when performing joins.

To find the MIN() or MAX() value for a specific indexed column.

To sort or group a table if the sorting or grouping is done on a leftmost prefix of a usable key.

The CHAR and VARCHAR types

The length of a CHAR column is fixed to the length that you declare when you create the table. The length
can be any value from 0 to 255. When CHAR values are stored, they are right-padded with spaces to the
specified length. When CHAR values are retrieved, trailing spaces are removed. Values in VARCHAR
columns are variable-length strings.

Data Definition Statements


Alter , create, drop, rename
Data Manipulation Statements
delete,insert, call,load data infile, truncate, update
Data loading statements.
LOAD MASTER DATA, LOAD DATA INFILE.

storage engines that act as handlers for different table types


MyISAM manages nontransactional tables. It provides high-speed storage and retrieval, as well as fulltext
searching capabilities. MyISAM is supported in all MySQL configurations, and is the default storage engine.
The MEMORY storage engine provides in-memory tables.
The MERGE storage engine allows a collection of identical MyISAM tables to be handled as a single table.
Like MyISAM, the MEMORY and MERGE storage engines handle nontransactional tables, and both are also
included in MySQL by default
The InnoDB and BDB storage engines provide transaction-safe tables. To maintain data integrity, InnoDB
also supports FOREIGN KEY referential-integrity constraints. .
A stored routine is a set of SQL statements that can be stored in the server. Once this has been done,
clients don't need to keep reissuing the individual statements but can refer to the stored routine instead

The Hypertext Transfer Protocol (HTTP) is a stateless technology, meaning that each individual HTML page
is an unrelated entity. HTTP has no method for tracking users or retaining variables as a person traverses
a site.

Drupal

The Drupal flow


nodes—the data pool --> modules --> blocks and menus --> user permissions --> site template
Drupal - A framework for building dynamic web sites offering a broad range of features and services
including user administration, publishing workflow, discussion capabilities, news aggregation, metadata
functionalities using controlled vocabularies and XML publishing for content sharing purposes. A Drupal
installation is generally comprised of a mix of core and contributed modules.

All content on a Drupal website is stored and treated as "nodes." A node is any posting, such as a page,
poll, story, forum text, or blog entry. Comments are not stored as nodes but are always tied to one.
the nodes module manages these nodes. This module is what lets you:
• List, sort through, and manage all the content on your site;
• Set norms for how all posts are displayed; and, 
• List and configure the "content types" for your site, and create new ones. 

The Content Construction Kit allows you to add custom fields to any of the content types using a web interface.
CCK is actually a group of modules. They include:
• Text 
• Number 
• Nodereference 
• Userreference 
• Optionwidgets 
• Fieldgroup 

S-ar putea să vă placă și