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

41⟩ What are the main error types in PHP and how do they differ?

In PHP there are three main type of errors:

Notices - Simple, non-critical errors that are occurred during the script execution. An example of a Notice would be accessing an undefined variable.

Warnings - more important errors than Notices, however the scripts continue the execution. An example would be include() a file that does not exist.

Fatal - this type of error causes a termination of the script execution when it occurs. An example of a Fatal error would be accessing a property of a non-existent object or require() a non-existent file.

Understanding the error types is very important if you are new to programming because they help you understand what is going on during the development, and they will help you know what you should look for in the code during debugging.

 234 views

42⟩ What are the __construct() and __destruct() methods in a PHP class?

All objects in PHP have Constructor and Destructor methods built-in. The Constructor method is called immediately after a new instance of the class is being created, and it's used to initialize class properties. The Destructor method takes no parameters.

Understanding these two in PHP means that the candidate knows the very basics of OOP in PHP.

 212 views

43⟩ Explain how to execute a PHP script using command line?

PHP script using command line can be executed using SAPI (Server Application programming Interface). Using SAPI Command Line Interface the PHP code can be passed to execute directly

Example:

Php -r 'print_r(get_defined_constanrs());'

From a shell, php -v will display whether the SAPI is CLI or CGI

 214 views

44⟩ How does one prevent the following Warning 'Warning Cannot modify header information - headers already sent' and why does it occur in the first place?

Do not output anything to the browser before using code that modifies the HTTP headers. Once you call echo or any other code that clears the buffer you can no longer set cookies or headers. That is also true for error messages, so if an error happens before you use the header command and the INI directive display_errors is set then that will also cause that error to show.

 253 views

46⟩ What is the purpose of _FUNCTION_ constant?

_FUNCTION_ − The function name. (Added in PHP 4.3.0) As of PHP 5 this constant returns the function name as it was declared (case-sensitive). In PHP 4 its value is always lowercased.

 209 views

48⟩ What is NULL in PHP context?

NULL is a special type that only has one value: NULL. To give a variable the NULL value, simply assign it like this −

$my_var = NULL;

The special constant NULL is capitalized by convention, but actually it is case insensitive; you could just as well have typed −

$my_var = null;

A variable that has been assigned NULL has the following properties:

It evaluates to FALSE in a Boolean context.

It returns FALSE when tested with IsSet() function.

 198 views

53⟩ How will you locate a string within a string in PHP?

The strpos() function is used to search for a string or character within a string. If a match is found in the string, this function will return the position of the first match. If no match is found, it will return FALSE. Let's see if we can find the string "world" in our string −

<?php

echo strpos("Hello world!","world");

?>

This will produce following result −

6

 200 views

55⟩ What are rules for naming a PHP variable?

Rules for naming a variable are following −

Variable names must begin with a letter or underscore character.

A variable name can consist of numbers, letters, underscores but you cannot use characters like + , - , % , ( , ) . & , etc

 213 views