Question #1 – How array_walk function works in PHP?
- original array
-
An callback function, with use of we update the array.
Question #2 – What is the difference between $message and $$message?
Question #3 – How to achieve Multilevel inheritance in PHP?
//base class class a{} //parent class extend the base class class bextends a{} //chid class extend the parent class class c extends b{}
Question #4 – How to get 2nd highest salary of employee, if two employee may have same salary?
select salary from employee group by salary order by salary limit 1,1
Question #5 – require_once(), require(), include().What is difference between them?
Question #6 – What type of inheritance supports by PHP?
- Single Inheritance – Support by PHP
- Multiple Inheritance – Not support
- Hierarchical Inheritance – Support by PHP
- Multilevel Inheritance – Support by PHP
Question #7 – How do you call a constructor for a parent class?
parent::constructor($value);
Question #8 – How to find duplicate email records in users table?
SELECT u1.first_name, u1.last_name, u1.email FROM users as u1 INNER JOIN ( SELECT email FROM users GROUP BY email HAVING count(id) > 1 ) u2 ON u1.email = u2.email;
Session Path: /tmp folder in server
$url='http://www.web-technology-experts-notes.in'; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 0); curl_setopt($ch, CURLOPT_HTTPHEADER, array( 'headerKey: HeaderValue ', 'Content-Type: application/json', "HTTP_X_FORWARDED_FOR: xxx.xxx.x.xx" )); echo curl_exec($ch); curl_close($ch);
Question #13 – How can we prevent SQL-injection in PHP?
Question #14 – How to set header in CURL?
curl_setopt($ch, CURLOPT_HTTPHEADER, Array("Content-Type: text/xml"));
asort() – sort associative arrays in ascending order, according to the value.
ksort() – sort associative arrays in ascending order, according to the key.
arsort() – sort associative arrays in descending order, according to the value.
rsort() – sort arrays in descending order.
krsort() – sort associative arrays in descending order, according to the key.
array_multisort() – sort the multi dimension array.
usort()- Sort the array using user defined function.
Question #16 – How to redirect https to http URL and vice versa in .htaccess?
RewriteEngine On RewriteCond %{HTTPS} on RewriteRule (.*) http://%{HTTP_HOST}%{REQUEST_URI} [R=301,L]
Redirect http to https
RewriteEngine on RewriteCond %{HTTPS} off RewriteRule ^(.*)$ https://%{HTTP_HOST}/$1 [R=301,L]
Question #17 – What are benefits of .htaccess?
- Routing the URL
- Mange Error Pages for Better SEO
- Redirection pages
- Detect OS (like Mobile/Laptop/Ios/Android etc)
- Set PHP Config variable
- Set Environment variable
- Allow/Deny visitors by IP Address
- Password protection for File/Directory
- Optimize Performance of website
- Improve Site Security
- mysql_fetch_row()
- mysql_fetch_array()
- mysql_fetch_object()
- mysql_fetch_assoc()
Question #19 – What is the use of explode() function ?
Question #20 – What is the difference between explode() and split() functions?
Question #21 – What is the use of mysql_real_escape_string() function?
Question #22 – Write down the code for save an uploaded file in php.
if ($_FILES[“file”][“error”] == 0)
{
move_uploaded_file($_FILES[“file”][“tmp_name”],
“upload/” . $_FILES[“file”][“name”]);
echo “Stored in: ” . “upload/” . $_FILES[“file”][“name”];
}
Question #23 – How to create a text file in php?
$filename = “/home/user/guest/newfile.txt”;
$file = fopen( $filename, “w” );
if( $file == false )
{
echo ( “Error in opening new file” ); exit();
}
fwrite( $file, “This is a simple testn” );
fclose( $file );
Question #24 – How to strip whitespace (or other characters) from the beginning and end of a string ?
Question #25 – What is output of following?
$a = '10'; $b = &$a; $b = "2$b"; echo $a; echo $b;
Output
210 210
Question #26 – What are Traits?
trait users { function getUserType() { } function getUserDescription() { } function getUserDelete() { } } class ezcReflectionMethod extends ReflectionMethod { use users; } class ezcReflectionFunction extends ReflectionFunction { use users; }
Question #27 – How to extend a class defined with Final?
Question #28 – What is full form of PSRs?
Question #29 – How do you execute a PHP script from the command line?
- Get the php.exe path from server (My PHP path is : D:wampbinphpphp5.5.12)
- In environment variable, Add this path path under PATH variable.
- Re-start the computer.
- Now, you can execute php files from command file.
php index.php
Question #30 – How to repair the session?
REPAIR TABLE tablename
REPAIR TABLE tablename QUICK
Read more about the best programming laptop
REPAIR TABLE tablename EXTENDED
Question #31 – What is stdClass?
stdClass is used to create the new Object. For Example
$newObj = new stdClass(); $newObj->name='What is your name?'; $newObj->description='Tell me about yourself?'; $newObj->areYouInIndia=1; print_r($newObj);
Output
stdClass Object ( [name] => What is your name? [description] => Tell me about yourself? [areYouInIndia] => 1 )
ini_set('display_errors', 1); ini_set('display_startup_errors', 1); error_reporting(E_ALL);
OR
Add following code in .htacess
php_flag display_startup_errors on php_flag display_errors on php_flag html_errors on php_flag log_errors on
Question #34 – What are different type of errors?
E_WARNING: Run-time warning that does not cause script termination.
E_PARSE: Compile time parse error.
E_NOTICE: Run time notice caused due to error in code.
E_CORE_ERROR: Fatal errors that occur during PHP’s initial startup.
E_CORE_WARNING: Warnings that occur during PHP’s initial startup.
E_COMPILE_ERROR: Fatal compile-time errors indication problem with script.
E_USER_ERROR: User-generated error message.
E_USER_WARNING: User-generated warning message.
E_USER_NOTICE: User-generated notice message.
E_STRICT: Run-time notices.
E_RECOVERABLE_ERROR: Catchable fatal error indicating a dangerous error
E_ALL: Catches all errors and warnings
class MyClass1 { private $nonStaticMember = 'nonStaticMember member Called.'; public function funcName() { return $this->nonStaticMember; } } $classObj = new MyClass1(); echo $classObj->funcName();//nonStaticMember member Called.
Example of use of SELF
class MyClass2 { private static $staticMember = 'staticMember member Called.'; public function funcName() { return $this::$staticMember; } } $classObj = new MyClass2(); echo $classObj->funcName(); //staticMember member Called.