PHP FAQ




What is PHP?

PHP:  Hypertext Preprocessor is a widely used, general-purpose scripting language that was originally designed  to produce dynamic web pages for web development
A server side scripting language widely used for web applications
PHP is an interpreted language



What’s the difference between include and require?

 Both syntax are used for including the files in the php files , but the difference is ,  If the file is not found by require(), it will cause a fatal error and stop the execution of the script. If the file is not found by include(), a warning will be issued, but execution will not stop .
 


What is the Session?

 Session is used for state management; Sessions allow data or information to be shared in all page of the website. Session variable is used to hold values of the current session, Session data is temporary and information is available until the user left the website URL. Each session is identified by a unique Id number for every visitor, The first step to use PHP session in the PHP page is to start the session with session_start(); example: session_start(); $_SESSION[‘test’]=1;
 


What is the difference between $message and $$message?

 $message is used to store variable data. $$message can be used to store variable of a variable.
 


How do you define a constant?

Constants in PHP are defined using define() directive, like define("MYCONSTANT", 100);



Will comparison of string "10" and integer 11 work in PHP?

 Yes, internally PHP will cast everything to the integer type, so numbers 10 and 11 will be compared.



What is ternary conditional operator in PHP?

 Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.


 
How will you find out the number of parameters passed into function in PHP?

  func_num_args() function returns the number of parameters/arguments passed to a function in PHP.


 
What is the difference between accessing a class method via -> and via ::?

In PHP, :: is allowed to access methods that can perform static operations, i.e. those, which do not require object initialization.


 
Are objects passed by value or by reference?

 Everything is passed by value. In PHP-4 version  it's true, BUT in PHP-5 version its not - all objects are passed by reference.
 


How will you  call a constructor for a parent class?

 parent::constructor($value)



What’s the special meaning of __sleep and __wakeup?

               __sleep returns the array of all the variables than need to be saved, while __wakeup retrieves them.
 


Would you initialize your strings with single quotes or double quotes in PHP?

 Since the data inside the single-quoted string is not parsed for variable substitution, it’s always a better idea speed-wise to initialize a string with single quotes, unless you specifically need variable substitution.



What’s the difference between htmlentities() and htmlspecialchars()?

htmlspecialchars only takes care of <, >, single quote ‘, double quote " and ampersand. htmlentities translates all occurrences of character sequences that have different meaning in HTML.


 
What’s the difference between md5(), crc32() and sha1() crypto on PHP?

The main difference is the length of the hash code generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value.



What is ternary conditional operator in PHP?

 Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.


 
How will you find out the number of parameters passed into function in PHP?

func_num_args() function returns the number of parameters/arguments passed to a function in PHP.


 
What’s the difference between md5(), crc32() and sha1() crypto on PHP?
 
The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.



If md5() generates the most secure hash, why would you ever use the less secure crc32() and sha1()?
 
 Crypto usage in PHP is simple, but that doesn’t mean it’s free. First off, depending on the data that you’re encrypting, you might have reasons to store a 32-bit value in the database instead of the 160-bit value to save on space. Second, the more secure the crypto is, the longer is the computation time to deliver the hash value. A high volume site might be significantly slowed down, if frequent md5() generation is required.
 


How can we submit a form without a submit button?
 

The main idea behind this is to use Java script submit() function in order to submit the form without clicking any submit button
 


how many ways we can retrieve the data in the result set ?

1. mysql_fetch_row. 2. mysql_fetch_array 3. mysql_fetch_object 4. mysql_fetch_assoc



How can we create a database using PHP and MySQL?

We can create MySQL database with the use of mysql_create_db(“Database Name”)


 
What is the difference between the functions unlink and unset?

unlink() is a function for file system handling. It will simply delete the file in context. unset() is a function for variable management. It will make a variable undefined


 
How can we know the count/number of elements of an array?

 a) sizeof($array) – This function is an alias of count() 
b) count($urarray) – This function returns the number of elements in an array.


 
What is the maximum length of a table name, a database name, or a field name in MySQL?

 Database name: 64 characters Table name: 64 characters Column name: 64 characters
 


What is the difference between PHP4 and PHP5?

 HP4 cannot support oops concepts and Zend engine 1 is used. PHP5 supports oops concepts and Zend engine 2 is used. Error supporting is increased in PHP5. XML and SQLLite will is increased in PHP5
 


What is meant by nl2br()?

 nl2br() inserts a HTML tag 

before all new line characters in a string. echo nl2br(“god bless you”); output: god bless
 


How can we get the value of current session id?

 session_id() returns the session id for the current session.



What is use of header() function in php ?

The header() function sends a raw HTTP header to a client.We can use herder() function for redirection of pages. It is important to notice that header() must be called before any actual output is seen..


 
What is htaccess? Why do we use this and Where?

htaccess files are configuration files of Apache Server which provide a way to make configuration changes on a per-directory basis. A file, containing one or more configuration directives, is placed in a particular document directory, and the directives apply to that directory, and all subdirectories thereof.
 


How can we get second of the current time using date function?

 $second = date("s");


 
How can we get the browser properties using PHP?

 By using $_SERVER['HTTP_USER_AGENT']



What is session_set_save_handler in PHP?

session_set_save_handler() sets the user-level session storage functions which are used for storing and retrieving data associated with a session. This is most useful when a storage method other than those supplied by PHP sessions is preferred. i.e. Storing the session data in a local database.


 
What is CURL?

CURL means Client URL Library curl is a command line tool for transferring files with URL syntax, supporting FTP, FTPS, HTTP, HTTPS, SCP, SFTP, TFTP, TELNET, DICT, LDAP, LDAPS and FILE. curl supports SSL certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, user+password authentication (Basic, Digest, NTLM, Negotiate, kerberos…), file transfer resume, proxy tunneling and a busload of other useful tricks. CURL allows you to connect and communicate to many different types of servers with many different types of protocols. libcurl currently supports the http, https, ftp, gopher, telnet, dict, file, and ldap protocols. libcurl also supports HTTPS certificates, HTTP POST, HTTP PUT, FTP uploading, HTTP form based upload, proxies, cookies, and user+password authentication.


 
What is Joomla?

 Joomla is a content management system. Powerful online applications and web sites are build using Joomla. Joomla is an open source CMS tool. Clients can easily manage their web sites with minimal amount of instructions. It is highly extensible. Joomla runs off PHP or MySQL. Joomla is used to create, maintain a structured, flexible portal, add or edit content, changes the look and feel of the site. PHP scripting is used and persisted most of its data / information in MySQL database


 
What is zend engine?

 Zend Engine is used internally by PHP as a complier and runtime engine. PHP Scripts are loaded into memory and compiled into Zend opcodes


 
What is the difference between echo and print statement in PHP?

 Echo can accept multiple expressions while print cannot. With respect to performance echo is faster than print since it does not return a value. Print returns 1 or 0 depending on the success.


 
What is CAPTCHA?

 CAPTCHA is a test to determine if the user using the system (usually a web form) is a human. It identifies this by throwing challenges to users. Depending on the responses the identification can be made. E,g Answering to identification of distorted images. Captcha Creator is a PHP Script that generates Strong Captchas



difference between Notify URL and Return URL?
 
 Notify URL and Return URL is used in Paypal Payment Gateway integration. Notify URL is used by PayPal to post information about the transaction. Return URL is sued by the browser; A url where the user needs to be redirected on completion of the payment process.


 
What is the use of PEAR in php?

PEAR is known as PHP Extension and Application Repository. It provides structured library to the PHP users and also gives provision for package maintenance.


 
What is difference between require_once(), require(), include()?

 require() includes and evaluates a specific file, if the file is not found then it shows a Fatal Error. require_once() includes only the file which is not being included before. It is used to be recommended for the files where you have lots of functions stored. include() includes the file, even if the file is not found, but it gives a warning to the user to include().


 
What is the use of super-global arrays in PHP?

Super global arrays are the built in arrays that can be used anywhere. They are also called as auto-global as they can be used inside a function as well. The arrays with the longs names such as $HTTP_SERVER_VARS, must be made global before they can be used in an array. This $HTTP_SERVER_VARS check your php.ini setting for long arrays.


 
What is the use of $_Server and $_Env?

$_SERVER and $_ENV arrays contain different information. The information depends on the server and operating system being used. Most of the information can be seen of an array for a particular server and operating system. The syntax is as follows: foreach($_SERVER as $key =>$value) { echo “Key=$key, Value=$value ”; }


 
What is the difference between mysql_fetch_object and mysql_fetch_array?

 MySQL fetch object will collect first single matching record where mysql_fetch_array will collect all matching records from the table in an array


 
What is the difference between ereg_replace() and eregi_replace()?

 eregi_replace() function is identical to ereg_replace() except that it ignores case distinction when matching alphabetic characters.



How can we destroy the session, how can we unset the variable of a session?

session_unregister() - Unregister a global variable from the current session session_unset() - Free all session variables


 
What’s the difference between md5(), crc32() and sha1() crypto on PHP?

The major difference is the length of the hash generated. CRC32 is, evidently, 32 bits, while sha1() returns a 128 bit value, and md5() returns a 160 bit value. This is important when avoiding collisions.



What is meant by MIME?

MIME is Multipurpose Internet Mail Extensions is an Internet standard for the format of e-mail. However browsers also uses MIME standard to transmit files. MIME has a header which is added to a beginning of the data. When browser sees such header it shows the data as it would be a file


 
What are the differences between mysql_fetch_array(), mysql_fetch_object(), mysql_fetch_row()?

mysql_fetch_array() -> Fetch a result row as a combination of associative array and regular array. mysql_fetch_object() -> Fetch a result row as an object. mysql_fetch_row() -> Fetch a result set as a regular array().


 
What is meant by nl2br()?

nl2br() inserts a HTML tag 

before all new line characters in a string.



 
   
TekTipsDownload
GateExam
Academic Projects
TekTipsExperts
Android