PHP Interview question Important - fresher

 




1)  List some of the features of PHP7.

Scalar type declarations

Return type declarations

Null coalescing operator (??)

Spaceship operator

Constant arrays using define()

Anonymous classes

Closure::call method

Group use declaration

Generator return expressions

Generator delegation

Space ship operator


2) Magic Constants

Magic constants are the predefined constants in PHP which get changed on the basis of their use. They start with double underscore (__) and ends with double underscore.


They are similar to other predefined constants but as they change their values with the context, they are called magic constants.


There are nine magic constants in PHP. In which eight magic constants start and end with double underscores (__).


__LINE__

__FILE__

__DIR__

__FUNCTION__

__CLASS__

__TRAIT__

__METHOD__

__NAMESPACE__

ClassName::class


3) PHP Data Types

PHP data types are used to hold different types of data or values. PHP supports 8 primitive data types that can be categorized further in 3 types:


Scalar Types (predefined)

Compound Types (user-defined)

Special Types


4) How many types of array are there in PHP?

There are three types of array in PHP:


Indexed array: an array with a numeric key.

Associative array: an array where each key has its specific value.

Multidimensional array: an array containing one or more arrays within itself.


5) Explain some of the PHP array functions?

There are many array functions in PHP:


array()

array_change_key_case()

array_chunk()

count()

sort()

array_reverse()

array_search()

array_intersect()


6) Explain some of the PHP string functions?

There are many array functions in PHP:


strtolower()

strtoupper()

ucfirst()

lcfirst()

ucwords()

strrev()

strlen()



7) How can you submit a form without a submit button?

You can use JavaScript submit() function to submit the form without explicitly clicking any submit button




8) Explain setcookie() function in PHP?


9) What is a session?

10)  What is the method to register a variable into a session?

11)  What is $_SESSION in PHP?

12) What is PHP session_start() and session_destroy() function?

13)  What is the difference between session and cookie?

14) Write syntax to open a file in PHP?

     resource fopen ( string $filename , string $mode [, bool $use_include_path = false [, resource $context ]] )  


15) How to read a file in PHP?

PHP file read functions are given below:


fread()

fgets()

fgetc()


16) How to write in a file in PHP?

    PHP fwrite() and fputs() functions are used to write data into file. To write data into a file, you need to use w, r+, w+, x, x+, c or c+ mode.

17)  How to delete file in PHP?

    bool unlink (string $filename)      

18) How to upload file in PHP?

The move_uploaded_file() function is used to upload file in PHP.


bool move_uploaded_file ( string $filename , string $destination )    

19)How to download file in PHP?

The readfile() function is used to download the file in PHP.


int readfile ( string $filename ) 


20) What are the different types of errors in PHP?

There are 3 types of error in PHP.


Notices:These are non-critical errors. These errors are not displayed to the users.

Warnings:These are more serious errors, but they do not result in script termination. By default, these errors are displayed to the user.

Fatal Errors:These are the most critical errors. These errors may cause due to immediate termination of script.


21) What is htaccess in PHP?


22) Explain PHP explode() function.

The PHP explode() function breaks a string into an array.


23) Explain PHP split() function.

The PHP split() function splits string into an array by regular expression.


24) How can we get IP address of a client in PHP?

$_SERVER["REMOTE_ADDR"];  

25) What is the meaning of a Persistent Cookie?

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.


26) What is the use of the function 'imagetypes()'?

imagetypes() gives the image format and types supported by the current version of GD-PHP.


https://www.naukri.com/code360/library/php-oops-interview-questions


No comments:

Post a Comment

Pages