Important Junior Developer PHP Interview Questions
Q – 1 Please explain is it possible to use COM component in PHP?
Ans- Yes, it’s possible to integrate (Distributed) Component Object Model components ((D)COM) in PHP scripts which is provided as a framework.
Q – 2 Tell me whether it is possible to share a single instance of a Memcache between multiple PHP projects?
Ans- Yes, it is possible to share a single instance of Memcache between multiple projects. Memcache is a memory store space, and you can run memcache on one or more servers. You can also configure your client to speak to a particular set of instances.
So, you can run two different Memcache processes on the same host and yet they are completely independent. Unless, if you have partitioned your data, then it becomes necessary to know from which instance to get the data from or to put into.
Q – 3 Explain what does the unset() function means?
Ans- The unset() function is dedicated for variable management. It will make a variable undefined.
Q – 4 How to update Memcached when you make changes to PHP?
Ans- When PHP changes you can update Memcached by
• Clearing the Cache proactively: Clearing the cache when an insert or update is made
• Resetting the Cache: It is similar to the first method but rather than just deleting the keys and waiting for the next request for the data to refresh the cache, reset the values after the insert or update.
Q – 5 Do you know what does $GLOBALS means?
Ans- $GLOBALS is associative array including references to all variables which are currently defined in the global scope of the script.
Q – 6 Explain me what is the goto statement useful for?
Ans- The goto statement can be placed to enable jumping inside the PHP program. The target is pointed by a label followed by a colon, and the instruction is specified as a goto statement followed by the desired target label.
Q – 7 Do you know what is the function mysql_pconnect() usefull for?
Ans- mysql_pconnect() ensure a persistent connection to the database, it means that the connection do not close when the the PHP script ends.
Q – 8 Explain me what is the meaning of a Persistent Cookie?
Ans- A persistent cookie is permanently stored in a cookie file on the browser’s computer. By default, cookies are temporary and are erased if we close the browser.
Q – 9 Explain how can PHP and Javascript interact?
Ans- PHP and Javascript cannot directly interacts since PHP is a server side language and Javascript is a client side language. However we can exchange variables since PHP is able to generate Javascript code to be executed by the browser and it is possible to pass specific variables back to PHP via the URL.
Q – 10 Tell me how to find current date and time?
Ans- The date() function provides you with a means of retrieving the current date and time, applying the format integer parameters indicated in your script to the timestamp provided or the current local time if no timestamp is given. In simplified terms, passing a time parameter is optional – if you don’t, the current timestamp will be used.
Q – 11 Explain what are the two main string operators?
Ans- The first is the concatenation operator (‘.’), which returns the concatenation of its right and left arguments. The second is (‘.=’), which appends the argument on the right to the argument on the left.
Q – 12 Tell me what is the use of “enctype” attribute in a html form?
Ans- The enctype attribute determines how the form-data should be encoded when submitting it to the server. We need to set enctype as “multipart/form-data” when we are using a form for uploading files
Q – 13 Explain what is the difference between $var and $$var?
Ans- They are both variables. But $var is a variable with a fixed name. $$var is a variable who’s name is stored in $var. For example, if $var contains “message”, $$var is the same as $message.
Q – 14 Tell me what is the difference between ereg_replace() and eregi_replace()?
Ans- The function eregi_replace() is identical to the function ereg_replace() except that it ignores case distinction when matching alphabetic characters.
Q – 15 Explain me what is the use of header() function in php?
Ans- The header() function sends a raw HTTP header to a client browser. Remember that this function must be called before sending the actual out put. For example, You do not print any HTML element before using this function.
Q – 16 Tell me what is the use of the function htmlentities?
Ans- htmlentities Convert all applicable characters to HTML entities This function is identical to htmlspecialchars() in all ways, except with htmlentities(), all characters which have HTML character entity equivalents are translated into these entities.
Q – 17 Explain what does $_SERVER means?
Ans- $_SERVER is an array including information created by the web server such as paths, headers, and script locations.
Q – 18 Tell me how is the ternary conditional operator used in PHP?
Ans- It is composed of three expressions: a condition, and two operands describing what instruction should be performed when the specified condition is true or false as follows:
Expression_1 ? Expression_2 : Expression_3;
Q – 19 Tell me is it possible to submit a form with a dedicated button?
Ans- It is possible to use the document.form.submit() function to submit the form. For example:
Q – 20 Explain me is multiple inheritance supported in PHP?
Ans- PHP includes only single inheritance, it means that a class can be extended from only one single class using the keyword ‘extended’.
Q – 21 Tell me how to execute an sql query? How to fetch its result?
Ans-
$my_qry = mysql_query(“SELECT * FROM `users` WHERE `u_id`=’1′; “);
$result = mysql_fetch_array($my_qry) or die (‘Error: Unable to get data.’);
echo $result[‘First_name’];
Q – 22 Tell me what does the scope of variables means?
Ans- The scope of a variable is the context within which it is defined. For the most part all PHP variables only have a single scope. This single scope spans included and required files as well.
Q – 23 Tell me how can we connect to a MySQL database from a PHP script?
Ans- To be able to connect to a MySQL database, we must use mysql_connect() function as follows:
Q – 24 Tell us how to redirect a page in php?
Ans- The following code can be used for it,
header(“Location: http://www.globalguideline.com/”);
Q – 25 Tell me will a comparison of an integer 12 and a string “13” work in PHP?
Ans- “13” and 12 can be compared in PHP since it casts everything to the integer type.
Q – 26 Tell me what should we do to be able to export data into an Excel file?
Ans- The most common and used way is to get data into a format supported by Excel. For example, it is possible to write a .csv file, to choose for example comma as separator between fields and then to open the file with Excel.
Q – 27 Tell us how can we display the output directly to the browser?
Ans- To be able to display the output directly to the browser, we have to use the special tags .
Q – 28 Tell me how can we change the maximum size of the files to be uploaded?
Ans- We can change the maximum size of files to be uploaded by changing upload_max_filesize in php.ini.
Q – 29 Tell me how is it possible to remove escape characters from a string?
Ans- The stripslashes function enables us to remove the escape characters before apostrophes in a string.
Q – 30 Explain what is the main difference between require() and require_once()?
Ans- require() and require_once() perform the same task except that the second function checks if the PHP script is already included or not before executing it.
(same for include_once() and include())
Q – 31 Explain me what is x+ mode in fopen() used for?
Ans- Read/Write. Creates a new file. Returns FALSE and an error if file already exists
Q – 32 Tell me how to create a text file in php?
Ans-
$filename = “/home/user/guest/myTextFile.txt”;
$file = fopen( $filename, “w” );
if( $file == false )
{
echo ( “Error in opening new file” ); exit();
}
fwrite( $file, “This is a simple testn” );
fclose( $file );
Q – 33 Tell me how do you define a constant?
Ans- Using define() directive, like define (“MYCONSTANT”,150)
Q – 34 Tell me how is it possible to propagate a session id?
Ans- It is possible to propagate a session id via cookies or URL parameters.
Q – 35 Tell me is it possible to protect special characters in a query string?
Ans- Yes, we use the urlencode() function to be able to protect special characters.