Thursday, January 26, 2012

PHP OOPS Interview Questions & Answers


1) 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.
2) Name some languages which have object oriented language and characteristics?
Some of the languages which have object oriented languages present in them are ABAP, ECMA Script, C++, Perl, LISP, C#, Tcl, VB, Ruby, Python, PHP, etc. Popularity of these languages has increased considerably as they can solve complex problems with ease.
3) 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.
4) Explain the meaning of object in object oriented programming?
Languages which are called as object oriented almost implement everything in them as objects such as punctuations, characters, prototypes, classes, modules, blocks, etc. They were designed to facilitate and implement object oriented methods.
5) Explain about message passing in object oriented programming?
Message passing is a method by which an object sends data to another object or requests other object to invoke method. This is also known as interfacing. It acts like a messenger from one object to other object to convey specific instructions.
6) State about Java and its relation to Object oriented programming?
Java is widely used and its share is increasing considerably which is partly due to its close resemblance to object oriented languages such as C++. Code written in Java can be transported to many different platforms without changing it. It implements virtual machine.
7) What are the problems faced by the developer using object oriented programming language?
These are some of the problems faced by the developer using object oriented language they are: -
a) Object oriented uses design patterns which can be referred to as anything in general.
b) Repeatable solution to a problem can cause concern and disagreements and it is one of the major problems in software design.
8 ) 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.
9 ) 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.
10) Explain about the relationship between object oriented programming and databases?
Object oriented programming and relational database programming are almost similar in software engineering. RDBMS will not store objects directly and that’s where object oriented programming comes into play. Object relational mapping is one such solution.
11) 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.
12) 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.
13) Explain about abstraction?
Abstraction can also be achieved through composition. It solves a complex problem by defining only those classes which are relevant to the problem and not involving the whole complex code into play.
14) 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.
15) Name the different Creational patterns in OO design?
There are three patterns of design out of which Creational patterns play an important role the various patterns described underneath this are: -
a) Factory pattern
b) Single ton pattern
c) Prototype pattern
d) Abstract factory pattern
e) Builder pattern
16) Explain about realistic modeling?
As we live in a world of objects, it logically follows that the object oriented approach models the real world accurately. The object oriented approach allows you to identify entities as objects having attributes and behavior.
17) Explain about the analysis phase?
The anlaysis or the object oriented analysis phase considers the system as a solution to a problem in its environment or domain. Developer concentrates on obtaining as much information as possible about the problem. Critical requirements needs to be identified.
************************************************************************************************************
1) Explain the rationale behind Object Oriented concepts?
Object oriented concepts form the base of all modern programming languages. Understanding the basic concepts of object-orientation helps a developer to use various modern day programming languages, more effectively.
2) Explain about Object oriented programming?
Object oriented programming is one of the most popular methodologies in software development. It offers a powerful model for creating computer programs. It speeds the program development process, improves maintenance and enhances reusability of programs.
3) Explain what is an object?
An object is a combination of messages and data. Objects can receive and send messages and use messages to interact with each other. The messages contain information that is to be passed to the recipient object.
4) Explain the implementation phase with respect to OOP?
The design phase is followed by OOP, which is the implementation phase. OOP provides specifications for writing programs in a programming language. During the implementation phase, programming is done as per the requirements gathered during the analysis and design phases.
5) Explain about the Design Phase?
In the design phase, the developers of the system document their understanding of the system. Design generates the blue print of the system that is to be implemented. The first step in creating an object oriented design is the identification of classes and their relationships.
6) Explain about a class?
Class describes the nature of a particular thing. Structure and modularity is provided by a Class in object oriented programming environment. Characteristics of the class should be understandable by an ordinary non programmer and it should also convey the meaning of the problem statement to him. Class acts like a blue print.
7) 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.
8 ) 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.
9) Explain about multiple inheritance?
Inheritance involves inheriting characteristics from its parents also they can have their own characteristics. In multiple inheritance a class can have characteristics from multiple parents or classes. A sub class can have characteristics from multiple parents and still can have its own characteristics.
10) Explain about encapsulation?
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.
11) 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.
12) 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.
13) Explain about polymorphism?
Polymorphism helps a sub class to behave like a parent class. When an object belonging to different data types respond to methods which have a same name, the only condition being that those methods should perform different function.
14) Explain about overriding polymorphism?
Overriding polymorphism is known to occur when a data type can perform different functions. For example an addition operator can perform different functions such as addition, float addition etc. Overriding polymorphism is generally used in complex projects where the use of a parameter is more.
15) Explain about object oriented databases?
Object oriented databases are very popular such as relational database management systems. Object oriented databases systems use specific structure through which they extract data and they combine the data for a specific output. These DBMS use object oriented languages to make the process easier.
16) Explain about parametric polymorphism?
Parametric polymorphism is supported by many object oriented languages and they are very important for object oriented techniques. In parametric polymorphism code is written without any specification for the type of data present. Hence it can be used any number of times.
17) What are all the languages which support OOP?
There are several programming languages which are implementing OOP because of its close proximity to solve real life problems. Languages such as Python, Ruby, Ruby on rails, Perl, PHP, Coldfusion, etc use OOP. Still many languages prefer to use DOM based languages due to the ease in coding.
var gaJsHost = ((“https:” == document.location.protocol) ? “https://ssl.” : “http://www.”);
document.write(unescape(“%3Cscript src=’” + gaJsHost + “google-analytics.com/ga.js’ type=’text/javascript’%3E%3C/script%3E”));
try {
var pageTracker = _gat._getTracker(“UA-1855756-5″);
pageTracker._trackPageview();
} catch(err) {}

Thursday, January 12, 2012

Magento: Product details from Product ID.


Product details from Product ID

<?php
$model = Mage::getModel('catalog/product') //getting product model
 
$_product = $model->load($productid); //getting product object for particular product id
 
echo $_product->getShortDescription(); //product's short description
echo $_product->getDescription(); // product's long description
echo $_product->getName(); //product name
echo $_product->getPrice(); //product's regular Price
echo $_product->getSpecialPrice(); //product's special Price
echo $_product->getProductUrl(); //product url
echo $_product->getImageUrl(); //product's image url
echo $_product->getSmallImageUrl(); //product's small image url
echo $_product->getThumbnailUrl(); //product's thumbnail image url  
 
?>

If you don’t have product id , you can get like this
<?php
$model = Mage::getModel('catalog/product'); //getting product model
$collection = $model->getCollection(); //products collection
foreach ($collection as $product) //loop for getting products
{
    echo $product->getId().'<br/>';
 
}
?>

Wednesday, January 11, 2012

Magento: Price issue on product detail page.


This depends on which one you want to keep. The price at the top of the page is generally displayed as part of the "product type data". Take a look at template/catalog/product/view/type/simple.phtml, where you should see $this->getPriceHtml($_product);.
The price at the bottom of the catalog page is a little more complicated. If you take a look at layout/catalog.xml, the price block (product.clone_prices) is added to the block product.info.options.wrapper.bottom, which is then added to product.info.container1 and product.info.container2. Depending on the product, one of these will be echoed on the page. You can, however, just remove the line for product.clone_prices and that should remove the price.

Also I've noticed this within catalog.xml file:

<block type="catalog/product_view" name="product.clone_prices" as="prices" template="catalog/product/view/price_clone.phtml"/>

Monday, January 2, 2012

How to set a custom group of users


You can add a new group from the Magento admin area > Customers > Customer Groups > Add New Customer Group.
Once a customer registers, you can change the group he/she belongs to from the Magento admin area > Customers > Manage Customers. Click on the Edit link next to the customer and change the group from the Account Information > Customer Group. Click Save Customer.
Set the discount from Promotions > Catalog Price Rules > Add New Rule.
In the Customer Groups select the customers' groups for which the promotion is valid. Enter the other details, set the rule actions and conditions.  Finally, click Save Rule.
The above ten tips will hopefully help you resolve at least some of the Magento issues you have faced or are about to face.

Magento : Access denied issue

First you should log out from the Magento admin area and then log in again.

If the above does not help, you should reset the admin privileges. This can be done through the Magento admin area > System > Permissions > Roles > Administrators.

Click on the Role Resources option from the left menu and make sure that Resource Access is set to All.

Click on the Save Role button and the permissions will be reset.

How to disable the Compare products functionality

You can disable the Compare products functionality in Magento by following these steps:

    Edit app/code/core/Mage/Catalog/Helper/Product/Compare.php and change the following code:

public function getAddUrl($product)

{

return $this->_getUrl(’catalog/product_compare/add’, $this->_getUrlParams($product));

}

to

public function getAddUrl($product)

{

//return $this->_getUrl(’catalog/product_compare/add’, $this->_getUrlParams($product)); return false;

}

    Edit ./app/design/frontend/base/default/layout/catalog.xml (if you are using a different Magento theme, enter its name instead of default) and change the following code:

<block type="catalog/product_compare_sidebar" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/>

to

<!-- <block type="catalog/product_compare_sidebar" before="cart_sidebar" name="catalog.compare.sidebar" template="catalog/product/compare/sidebar.phtml"/> -->

    Flush the Magento cache from your Magento admin area > System > Cache Management.

How to redirect Magento to open through www


For SEO and usability purposes you may want to redirect your visitors to open your site only through www (http://www.yourdomain.com).
To do this in Magento, you should open the .htaccess file in the folder where your Magento is installed. In it locate the RewriteEngine on line and right after it add the following lines:
RewriteCond %{HTTP_HOST} ^yourdomain.com$ [NC]
RewriteRule ^(.*)$ http://www.yourdomain.com/$1 [R=301,L]
Once you do this, save the .htaccess file and log in to the Magento admin area > System > Configuration menu and from the left panel click the Web button.
Unfold the Unsecured set of options and change the Base URL option from http://yourdomain.com to http://www.yourdomain.com.
Save the changes and your Magento will start working through www.yourdomain.com only! 

How to enable Search Engine Friendly URLs in Magento


To enable Search Engine Friendly URLs in Magento, you have to log in to the Magento's administration area and click on the Configuration button. Under the Systemnavigation menu, switch to Web page from the sub-navigation panel on the left.
When the page loads, you will see blue lines which represent closed options tablets. Click on the Search Engines Optimization tab and turn on the Use Web Server Rewrites(mark as Yes). Click on the Save Config button and your Magento SEF URLs will be enabled.

How to reset Magento Admin Password


To change your Magento admin password, go to your cPanel > phpMyAdmin, select your Magento database, click the SQL tab and paste this query:
UPDATE admin_user SET password=CONCAT(MD5('sGnewpass'), ':sG') WHERE username='AdminUsername';

Note: You have to change newpass in the MD5('sGnewpass') with your new password, and change *AdminUsername* to your Magento admin username.
Execute the query by clicking the Go buttong and your password will be changed.

How to configure Magento to work with a new domain


There are two things you should do in order to configure Magento to work with a new domain:
  • Edit the Magento database
Go to your cPanel > phpMyAdmin. Select your Magento database from the  left menu, find the table called core_config_data and click on it.

Click the Browse tab and edit the first two fields:
web/unsecure/base_url
web/secure/base_url

by clicking the pen icon in front of each of them. Replace your old domain name with your new one and click the Go button to save the change.
  • Clear the Magento cache.
The Magento cache folder is located in your Magento installation directory > /var/cache. To clear the cache, simply delete the folder. 
Many Magento issues can be fixed just by deleting the cache.

Magento : How to speed up Magento

Many Magento issues are caused by slow performance.

1.The recommended way to speed up Magento's performance is to enable its Compilation function.  The performance increase is between 25%-50% on page loads.

You can enable Magento Compilation from your Magento admin panel > System > Tools > Compilation.

2..Modifying, I mean uncommenting few lines in your .htaccess file can speed up your magento site a looooot. Find these lines below and just remove # before them.

############################################

## enable apache served files compression

## http://developer.yahoo.com/performance/rules.html#gzip

# Insert filter

SetOutputFilter DEFLATE

# Netscape 4.x has some problems…

BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some online cialis more problems

BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine

BrowserMatch Buy Generic Drugs Without Prescription \bMSIE !no-gzip !gzip-only-text/html

# Don’t compress images

SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don’t deliver the wrong content

Header append Vary User-Agent env=!dont-vary

# enable resulting html compression

php_flag zlib.output_compression on

3.An easier way to improve Magento website speed is to turn on GZip compression via .htaccess. GZip compression is a kind of technique to compress textual content when it’s transferred from the web server to a user’s browser.

A single web page from a Magento site can be a few hundreds KB -one of my site shows its homepage size is 500KB when Yahoo homepage is 200KB! (you can check this by clicking Information View Document Size from FireFox developer’s tool bar.)

GZip compression can reduce page size significantly and transfer the data faster to your site visitors.

The files that can be compressed are text files such as XHTML, JavaScript or CSS. Image, video or other multi media files are already compressed.

Find the section for “mod_deflate.c” from your .htaccess file and uncomment the settings as follows:

<IfModule mod_deflate.c>

############################################

## enable apache served files compression

## http://developer.yahoo.com/performance/rules.html#gzip

# Insert filter

SetOutputFilter DEFLATE

# Netscape 4.x has some problems…

BrowserMatch ^Mozilla/4 gzip-only-text/html

# Netscape 4.06-4.08 have some more problems

BrowserMatch ^Mozilla/4\.0[678] no-gzip

# MSIE masquerades as Netscape, but it is fine

BrowserMatch \bMSIE !no-gzip !gzip-only-text/html

# Don’t compress images

SetEnvIfNoCase Request_URI \.(?:gif|jpe?g|png)$ no-gzip dont-vary

# Make sure proxies don’t deliver the wrong content

Header append Vary User-Agent env=!dont-vary

</IfModule>

############################################

## enable resulting html compression

php_flag zlib.output_compression on