Senior PHP Programmer

  Home  Computer Programming  Senior PHP Programmer


“Sr. PHP Programmer based Frequently Asked Questions by expert members with experience as Senior PHP Programmer. These questions and answers will help you strengthen your technical skills, prepare for the new job test and quickly revise the concepts”



202 Senior PHP Programmer Questions And Answers

61⟩ What PSR Standards do you follow? Why would you follow a PSR standard?

You should folow a PSR because coding standards often vary between developers and companies. This can cause issues when reviewing or fixing another developer's code and finding a code structure that is different from yours. A PSR standard can help streamline the expectations of how the code should look, thus cutting down confusion and in some cases syntax errors.

 200 views

62⟩ What is the difference between GET and POST?

☛ GET displays the submitted data as part of the URL, during POST this information is not shown as it's encoded in the request.

☛ GET can handle a maximum of 2048 characters, POST has no such restrictions.

☛ GET allows only ASCII data, POST has no restrictions, binary data are also allowed.

☛ Normally GET is used to retrieve data while POST to insert and update.

Understanding the fundamentals of the HTTP protocol is very important to have a good start as a PHP developer, and the differences between GET and POST are an essential part of it.

 233 views

63⟩ What is the use of the function htmlentities?

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.

 193 views

64⟩ How to connect to a URL in PHP?

It should also be clear that we will need to somehow be able to connect to a URL and view the contents of the page that the URL points to. What is the best way to do this? Well PHP provides a library called cURL that may already be included in your installation of PHP by default. cURL stands for client URL, and it allows you to connect to a URL and retrieve information from that page - like the HTML content of the page, the HTTP headers and their associated data, etc. You will see the use of cURL in our code below - don't worry if you've never used cURL before, it's fairly easy to understand!

 192 views

66⟩ What does MVC stand for and what does each component do?

MVC stands for Model View Controller.

The controller handles data passed to it by the view and also passes data to the view. It's responsible for interpretation of the data sent by the view and dispersing that data to the appropriate models awaiting results to pass back to the view. Very little, if any business logic should be occurring in the controller.

The model's job is to handle specific tasks related to a specific area of the application or functionality. Models will communicate directly with your database or other storage system and will handle business logic related to the results.

The view is passed data by the controller and is displayed to the user.

Overall, this question is worth knowing as the MVC design pattern has been used a lot in the last few years and is a very good design pattern to know. Even with more advanced flows that go down to repositories and entities, they still are following the same basic idea for the Controller and View. The Model is typically just split out into multiple components to handle specific tasks related to database data, business logic etc. The MVC design pattern helps draw a better understanding of what is being used, as a whole, in the industry.

 200 views

67⟩ How will you redirect a page using PHP?

The PHP header() function supplies raw HTTP headers to the browser and can be used to redirect it to another location. The redirection script should be at the very top of the page to prevent any other part of the page from loading. The target is specified by the Location: header as the argument to the header() function. After calling this function the exit() function can be used to halt parsing of rest of the code.

 194 views

68⟩ How will you read a file in php?

Once a file is opened using fopen() function it can be read with a function called fread(). This function requires two arguments. These must be the file pointer and the length of the file expressed in bytes.

 194 views

71⟩ Distinguish between urlencode and urldecode?

This method is best when encode a string to used in a query part of a url. it returns a string in which all non-alphanumeric characters except -_. have replece with a percentege(%) sign . the urldecode->Decodes url to encode string as any %and other symbole are decode by the use of the urldecode() function.

 204 views

72⟩ What is the use of 'print' in php?

This is not actually a real function, It is a language construct. So you can use with out parentheses with its argument list.

Example print('Global Guideline');

 177 views

73⟩ What are the differences between PHP constants and variables?

☛ There is no need to write a dollar sign ($) before a constant, where as in Variable one has to write a dollar sign.

☛ Constants cannot be defined by simple assignment, they may only be defined using the define() function.

☛ Constants may be defined and accessed anywhere without regard to variable scoping rules.

☛ Once the Constants have been set, may not be redefined or undefined.

 203 views

74⟩ How can you enable error reporting in PHP?

Check if "display_errors" is equal "on" in the php.ini or declare "ini_set('display_errors', 1)" in your script.

Then, include "error_reporting(E_ALL)" in your code to display all types of error messages during the script execution.

Enabling error messages is very important especially during the debugging process as you can instantly get the exact line that is producing the error and you can see also if the script in general is behaving correctly.

 194 views

75⟩ What is escaping to PHP?

The PHP parsing engine needs a way to differentiate PHP code from other elements in the page. The mechanism for doing so is known as 'escaping to PHP.'

 180 views

76⟩ What does ob_start do?

Makes it so PHP does not output anything. Companies ask this because many large frameworks wrap a bunch of code in ob_start() and ob_get_clean(). So understanding how that function works is pretty important.

 206 views

78⟩ What is the difference between $_GET and $_POST?

This is a great question because an interviewer can tell how deeply you understand HTTP and the request/response. If you don't have good understanding of HTTP protocol, google around and get a grasp on it.

Explain the HTTP protocol and how every request contains a method, generally(GET,POST,PUT,DELETE) and what each method signifies.

$_GET stores variables passed in url as query strings. $_POST stores variables past from using method = $_POST

 197 views

79⟩ What is the use of rand() in php?

It is used to generate random numbers. If called without the arguments it returns a pseudo-random integer between 0 and getrandmax(). If you want a random number between 6 and 12 (inclusive), for example, use rand(6, 12).

This function does not generate cryptographically safe values, and should not be used for cryptographic uses. If you want a cryptographically secure value, consider using openssl_random_pseudo_bytes() instead.

 199 views