Featured Post

What is the purpose of the php.ini file?

  The PHP configuration file,   php.ini , is the final and most immediate way to affect PHP's functionality. The php.ini file is read ea...

Showing posts with label PHP Functions. Show all posts
Showing posts with label PHP Functions. Show all posts

Difference between echo and print?

 

echoprint
Can output multiple strings    Outputs one string only
Faster    Slightly slower
No return value    Returns 1

Difference between Abstract class and Interfaces.

Abstract class:

  • Abstract class comes under partial abstraction.
  • Abstract classes can maintain abstract methods and non abstract methods.
  • In abstract classes, we can create the variables.
  • In abstract classes, we can use any access specifier.
  • By using 'extends' keyword we can access the abstract class features from derived class.
  • Multiple inheritance is not possible.

Interface:

  • Interface comes under fully abstraction.
  • Interfaces can maintain only abstract methods.
  • In interfaces, we can't create the variables.
  • In interface, we can use only public access specifier.
  • By using 'implement' keyword we can get interface from derived class.
  • By using interfaces multiple inheritance is possible.

The Difference Between Abstract Class and Interface in PHP

 

Introduction 

 
Before diving deep into the difference between abstract class and interfaceyou must understand one basic thing: these are two completely different classes that cannot be used as an alternative to one another.
 
Interface classes completely empty the shells while expecting child classes to implement everything for them. Abstract classes not only contain the common piece of information between the shells inside but also expect the child classes within to fill in the gaps.
 
Let us dive in a bit deeper to actually understand the difference minutely.
 
If you want to read about PHP Array questions then you can visit here. This will help you crack your PHP interviews.

What is Member Variable and Member function?

  Member Variable − These are the variables defined inside a class. This data will be invisible to the outside of the class and can be accessed via member functions. These variables are called attribute of the object once an object is created.

Member function − These are the function defined inside a class and are used to access object data.

SOLID Principles in PHP

This post is to provide an easy to understand idea about the implementation of one of the most “talked about” principles of Object Oriented Programming - SOLID principles. As a programmer, there might come a time when we are so consumed in finishing the task at hand that we forget the world around us. And in the very same world, somewhere lost are the programming principles that we read about and planned to use next time. So let’s try to look at the SOLID principles in one of the simplest way possible so that we can practice them while coding.

So let’s dig in to the SOLID principles at a glance.

  1. Single Responsibility: A Class should be responsible for a single task.
  2. Open-Close Principle: A Class should be open to extension and close to modification.
  3. Liskov Substitution: A derived Class can be substituted at places where base Class is used.
  4. Interface Segregation: Don’t make FAT Interfaces. i.e. Classes don’t have to override extra agreements that are not needed for that Class simply because it is there in interface.
  5. Dependency Inversion: Depend on abstractions, not on concretions. Not only high level Classes but low level Classes also depend on the abstractions in order to decouple the code.

What are different Clauses used in SQL?

 WHERE Clause: This clause is used to define the condition, extract and display only those records which fulfill the given condition.

Syntax:

SELECT column_name(s) 
 FROM table_name 
 WHERE condition;

GROUP BY Clause: It is used with SELECT statement to group the result of the executed query using the value specified in it. It matches the value with the column name in tables and groups the end result accordingly.

Syntax:

SELECT column_name(s)
 FROM table_name
 GROUP BY column_name;

HAVING clause: This clause is used in association with the GROUP BY clause. It is applied to each group of results or the entire result as a single group. It is much similar as WHERE clause but the only difference is you cannot use it without GROUP BY clause

Syntax:

 
SELECT column_name(s) 
 FROM table_name 
 GROUP BY column_name 
 HAVING condition;

ORDER BY clause: This clause is used to define the order of the query output either in ascending (ASC) or in descending (DESC). Ascending (ASC) is set as the default one but descending (DESC) is set explicitly.

Syntax:

SELECT column_name(s) 
 FROM table_name 
 WHERE condition 
 ORDER BY column_name ASC|DESC;

USING clause: USING clause comes in use while working with SQL JOIN. It is used to check equality based on columns when tables are joined. It can be used instead of the ON clause in JOIN.

Syntax:

SELECT column_name(s) 
 FROM table_name 
 JOIN table_name 
 USING (column_name);

Is PHP a strongly typed language?

No. PHP is a weakly typed or loosely typed language.

This means PHP does not require to declare data types of the variable when you declare any variable like the other standard programming languages C# or Java. When you store any string value in a variable, then the data type is the string and if you store a numeric value in that same variable then the data type is an Integer.

Sample code:

$var = "Hello"; //String
$var = 10; //Integer

PHP 5.5.0 Release

The PHP development team is proud to announce the immediateavailability of PHP 5.5.0. This release includes a large number of new features and bug fixes.
The key features of PHP 5.5.0 include:

Features and advantages of OBJECT ORIENTED PROGRAMMING?

  • One of the main advantages of OO programming is its ease of modification.
  • Objects can easily be modified and added to a system there by reducing maintenance costs.
  • OO programming is also considered to be better at modeling the real world than is procedural programming.
  • It allows for more complicated and flexible interactions.
  • OO systems are also easier for non-technical personnel to understand and easier for them to participate in the maintenance and enhancement of a system because it appeals to natural human cognition patterns.
  • For some systems, an OO approach can speed development time since many objects are standard across systems and can be reused.
  • Components that manage dates, shipping, shopping carts, etc. can be purchased and easily modified for a specific system.

List of Online PHP Codepads

Yes, there are some. Looking for a PHP version? I was looking for a PHP 5.1 codepad (run PHP code online for test purposes), but was not able to. I remember there was one, but I have not found it.
Here is the list I came up so far before you need to click through hundreds of search results:

CodepadPHP Version(s)Note
writecodeonline.com PHP 4.4.9 Legacy needs?
codepad.org PHP 5.2.5 Many languages, good history
ideone.com PHP 5.2.12 (pl0-gentoo) Many langauges, good history
freephptest.com PHP 5.2.17 Not very accessible
coderun.com (ide) PHP 5.3.1 Not suitable for quick testing
phpcodepad.com PHP 5.3.2 Not very accessible
codepad.viper-7.com PHP 5.2, PHP 5.3, PHP 5.4 + trunk A PHP coders paradise

Connection handling

Internally in PHP a connection status is maintained. There are 3 possible states:
  • 0 - NORMAL
  • 1 - ABORTED
  • 2 - TIMEOUT
When a PHP script is running normally the NORMAL state, is active. If the remote client disconnects the ABORTED state flag is turned on. A remote client disconnect is usually caused by the user hitting his STOP button. If the PHP-imposed time limit (see set_time_limit()) is hit, the TIMEOUT state flag is turned on.
You can decide whether or not you want a client disconnect to cause your script to be aborted. Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output. The default behaviour is however for your script to be aborted when the remote client disconnects. This behaviour can be set via the ignore_user_abort php.ini directive as well as through the corresponding php_value ignore_user_abort Apache httpd.conf directive or with the ignore_user_abort() function. If you do not tell PHP to ignore a user abort and the user aborts, your script will terminate. The one exception is if you have registered a shutdown function using register_shutdown_function(). With a shutdown function, when the remote user hits his STOP button, the next time your script tries to output something PHP will detect that the connection has been aborted and the shutdown function is called. This shutdown function will also get called at the end of your script terminating normally, so to do something different in case of a client disconnect you can use the connection_aborted() function. This function will return TRUE if the connection was aborted.

What is the use of friend function?

Friend function is best shared among a number of different classes. Such functions can be declared either as member functions of one class or as global functions. In either case they can be set to be friends of other classes, by using a friend specifier in the class that is admitting them. Such functions can use all attributes of the class which names them as a friend, as if they were themselves members of that class.
A friend declaration is essentially a prototype for a member function, but instead of requiring an implementation with the name of that class attached by the double colon syntax, a global function or member function of another class provides the match.
For this PHP 5.3+ implementation you will need a base class. A class that should be extended by the classes that need to have friends. This base class provides the friend-architecture, so that it will need to be coded only once.

Popular Posts