PHP Interview Questions and Answers Set 7

61. Are Parent constructors called implicitly inside a class constructor?

No, a parent constructor have to be called explicitly as follows:


62. What’s the difference between __sleep and __wakeup?

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

63. What is faster?

1- Combining two variables as follows:

$variable1 = ‘Hello ‘;

$variable2 = ‘World’;

$variable3 = $variable1.$variable2;


2- $variable3 = “$variable1$variable2”;

$variable3 will contain “Hello World”. The first code is faster than the second code especially for large large sets of data.

64. what is the definition of a session?

A session is a logical object enabling us to preserve temporary data across multiple PHP pages.

65. How to initiate a session in PHP?

The use of the function session_start() lets us activating a session.

66. How is it possible to propagate a session id?

It is possible to propagate a session id via cookies or URL parameters.

67. 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.

68. When sessions ends?

Sessions automatically ends when the PHP script finishs executing, but can be manually ended using the session_write_close().

69. What is the difference between session_unregister() and session_unset()?

The session_unregister() function unregister a global variable from the current session and the session_unset() function free all session variables.

70. What does $GLOBALS means?

$GLOBALS is associative array including references to all variables which are currently defined in the global scope of the script.