Change language

PHP Interview Questions and Answers | Set-2

We’ve already discussed some of the questions in PHP Interview FAQ | Set-1 . Here are some more related questions:
  • How can you enable error reporting in PHP?
    If you are getting errors and have no idea about these errors, you can use the built-in error_reporting()function. This function will give you information about the errors, where and why they occur. The best place to enable this feature is - the beginning of your PHP script. You can also set this function for a specific script, or you can set it for all scripts on your server by editing the php.inifile.
  • What are the main error types and how are they different?
    There are different types of errors in PHP, but it contains mainly four main types of errors:
    • Parse error or syntax error:This is a type of error made by the programmer in the program’s source code. Parsing errors can be caused by duties to open quotes, missing or extra parentheses, open parentheses, missing semicolons, etc.
    • Fatal error:This is a type of error where the PHP compiler understands PHP code, but it recognizes an undeclared function. This means that the function is called without a function definition.
    • Warning Errors . The root cause of warning errors is - missing file. This means that the PHP function is calling the missing file.
    • Error notification:This looks like an error warning. This means that something is wrong in the program, but it allows the script to execute.
  • What is inheritance in PHP?
    PHP inheritance means that a child class can inherit all properties and protected methods from its parent class, and the extension keyword is used to define inheritance.
  • Does PHP support multiple inheritance?
    PHP does not support multiple inheritance, but using interfaces in PHP or using traits in PHP instead of classes, we can implement this.
  • What are traits in PHP?
    A trait is a class type that allows multiple inheritance. Classes, case classes, objects, and traits can extend at most one class, but can extend multiple traits at the same time.
  • What is the difference between GET and POST?
    • GET:requests data from the specified resource. In this method, data is sent as URL parameters, which are usually strings of name and value pairs separated by ampersands (& amp;). 
      Syntax:
       
    • POST:In this method, data is sent to the server as a batch in a separate message with a processing script. The data sent by the POST method will not be visible in the URL. 
      Syntax:
       
  • What is the difference between unset() and unlink()?
    • Unlink() function:unlink() function - it is a built-in function in PHP that is used to delete a file. The filename of the file to be deleted is sent as a parameter, and the function returns True on success and False on error. The unlink() function in PHP takes two parameters filenameand context .
    • Unset() function:Unset ( ) - it is a built-in function in PHP that is used to remove content from a file by cleaning it up. This means that the function cleans up the contents of the file, rather than deleting it. The unset() function not only clears the contents of the file, but is also used to unset the variable, making it empty by accepting a variable of one parameter.
  • If x = 10 and y = "10", which returns the condition x === y? $x = 10; $y = "10" ; var_dump ( $x === $y ); ?> This will return bool (false) .
  • What are Nullable types in PHP?
    This function is new to PHP, Nullable adds an initial question mark indicating that the type can also be null. < tbody> function engineer():? int { return null; // Ok}
  • What is the maximum file size that can be uploaded with PHP?
    By default, the maximum upload size for PHP scripts is set by 128 megabytes. But you can change it, the maximum size of any file that can be uploaded to a website written in PHP is determined by the max_size values ​​that can be published or uploaded specified in the server’s php.inifile. In the case of the host server, you need to contact the administrator of the host server, but XAMPP has interpreters for scripts written in PHP and Perl. This helps create a local HTTP server for developers and gives them full physical and administrative access to the local server. Hence, it is the most widely used server and it is very easy to increase the file upload limit to the desired value on that server.
  • How can we increase the PHP script execution time?
    Use the built-in PHP function ini_set (option, value), where the parameters are the specified configuration option and the value to be set. It is used when you need to override a configuration value at runtime. This function is called from your own PHP code and will only affect the script that calls this function. Use init_set (’ max_execution_time & # 39 ;, 0) when you want to set unlimited script execution time. // Program runs in 3ns
    ini_set ( ’max_execution_time’ , 180); ?>
  • What is the difference between include() and require() functions?
    • include() function:this function is used to copy the entire contents of a file that is called inside a function, by text, into the file from which it is called. This happens before the server executes the code.
    • The require() function:The require() function performs the same functionality as include(). It also takes the required file and copies all the code into the file from which the require() function is called.
  • What are the three Public, Private and Protected access specifiers in PHP?
    • Shared modifier:this modifier is open for use both inside and outside the class.
    • Protected access modifier:this modifier is open for use internally the class in which it is defined and its parent or inherited classes.
    • Private modifier:This modifier is public for use in the class that defines it. (This cannot be accessed outside of the class means in the inherited class.)
  • Explain the behavior of the spacecraft operator?
    The spacecraft operator or combined comparison operator is denoted as "". It is a three-way comparison operator that can perform a comparison between two operands greater than, less than, and equal.
      This operator offers a combined comparison:
    • Return 0 if the values ​​on both sides are equal
    • Returns 1 if the value on the left is greater than
    • Returns -1 if the value on the right is greater than
  • What are the __construct() and __destruct() methods in the PHP class?
    • __construct() methods:Constructors - these are the most basic building blocks that determine the future object and its nature. We can say that Constructors - these are blueprints for creating objects, providing values ​​for member functions and member variables.
      function __construct() {// Initialize the object and its // properties by assigning values} 
    • __destruct() methods:destructors are used to destroy objects and are automatically called at the end of execution.
      function __destruct() {// Destroying the object or // clean up resources here} 
  • What are urlencode() and urldecode()?
    • urlencode() function: function urlencode() - it is a built-in function in PHP that is used to encode a URL. This function returns a string that contains all non-alphanumeric characters except -_. and is replaced by a percent sign (%) followed by two hexadecimal digits and spaces, encoded as plus signs (+).
    • urldecode() function: urldecode() function - it is a built-in function in PHP that is used to decode a URL encoded with the encoded() function.
  • How to remove line breaks from a line?
    A line break can be removed from a line with using the str_replace() function. The str_replace() function - is a built-in function in PHP that is used to replace all occurrences of a search string or an array of search strings with a replacement string or an array of replacement strings in a given string or array, respectively.
  • How to remove an extension from a string?
    There are three ways to remove an extension from a string. They are as follows
    • Using the built-in pathinfo function
    • Using the built-in basename function
    • Using the string substr and strrpos functions
  • How to check if the value of a variable is a number, alphanumeric or empty?
    You can use the is_numeric() functionto check if it is a number or no. The ctype_alnum()function is used to check if it is an alphanumeric value or not, and using the empty()function, it checks if the variable is empty or not.
  • Can HTML tags be removed from data?
    Yes, this is possible with the strip_tags()function. This function is a built-in function in PHP that is used to extract a string from HTML and PHP tags. This function returns a string with all NULL bytes, HTML and PHP tags extracted from the given $str.
  • Shop

    Best laptop for Sims 4

    $

    Best laptop for Zoom

    $499

    Best laptop for Minecraft

    $590

    Best laptop for engineering student

    $

    Best laptop for development

    $

    Best laptop for Cricut Maker

    $

    Best laptop for hacking

    $890

    Best laptop for Machine Learning

    $950

    Latest questions

    NUMPYNUMPY

    psycopg2: insert multiple rows with one query

    12 answers

    NUMPYNUMPY

    How to convert Nonetype to int or string?

    12 answers

    NUMPYNUMPY

    How to specify multiple return types using type-hints

    12 answers

    NUMPYNUMPY

    Javascript Error: IPython is not defined in JupyterLab

    12 answers

    Wiki

    Python OpenCV | cv2.putText () method

    numpy.arctan2 () in Python

    Python | os.path.realpath () method

    Python OpenCV | cv2.circle () method

    Python OpenCV cv2.cvtColor () method

    Python - Move item to the end of the list

    time.perf_counter () function in Python

    Check if one list is a subset of another in Python

    Python os.path.join () method