Skip to content

Instantly share code, notes, and snippets.

@RALMAZ
Last active January 5, 2018 18:41
Show Gist options
  • Save RALMAZ/bd4bbe4e099bd811e177372891096a68 to your computer and use it in GitHub Desktop.
Save RALMAZ/bd4bbe4e099bd811e177372891096a68 to your computer and use it in GitHub Desktop.
Test
?? php5 long text
+ self is for...
?? how to drop
+ mysql_drop_db()
?? partitioning
+
?? php5 self
+ self is for use...
?? operator is used
+ ===
?? how to rename file
+ rename(oldname, newname)
?? invoking
+ __callStatic()
?? sort by value
+ asort()
?? what are methods
+ These are the function defined
+ These are the functions in which
?? The following functions can be used from Exception class?
+ getMessage
+ getLine
+ getTraceAsString
?? Which is the correct way to profile a PHP function (without relying on 3rd party libraries and/or PHP extensions)
+ microtime(true)
?? You can extend the exception base class, but you can not override any of the preceding methods because they are declared as:
+ final
?? Which of the following is true about the singleton design pattern?
+ A singleton pattern means that a class can have only one instance object
?? Which of the following is useful for method overloading?
+ __call,__get,__set
?? Which of the following methods should be used for sending an email using the variables $to, $subject, and $body?
+ mail($to,$subject,$body)
?? What will be the output of the following code? var_dump (3*4);
+ int(12)
?? Which of the following will start a session?
+ session_start()
?? Which of the following is incorrect with respect to separating PHP code and HTML?
+ As PHP is a scripting language, HTML and PHP cannot be separated.
?? Which of the following will read an object into an array variable?
+ $array_variable = get_object_vars($object);
+ $array_variable = (array)$object;
?? Which of the following is correct about Mysqli and PDO?
+ Mysqli can only be used to access MySQL database while PDO can be used to access any DBMS
?? Which of the following characters are taken care of by htmlspecialchars?
+ All of these
?? Which function can be used to delete a file?
+ unlink()
?? What would occur if a fatal error was thrown in your PHP program?
+ The PHP program will stop executing at the point where the error occurred
?? What is the correct way to send a SMTP (Simple Mail Transfer Protocol) email using PHP?
+ mail($EmailAddress, «Subject», $MessageBody);
?? Which of the following is not a PHP magic constant?
+ __TIME__
?? Which of the following is used to maintain the value of a variable over different pages?
+ session_register()
?? Which of the following is not related to debugging in PHP?
+ watch
?? Should assert() be used to check user input?
+ No
?? Which function will suitably replace ‘X’ if the size of a file needs to be checked?
+ size
?? Which of the following is not a predefined constant?
+ CONSTANT
?? What will be the output of the following code?
<?php
$str=»Hello»;
$test=»lo»;
echo substr_compare($str, $test, -strlen($test), strlen($test)) === 0;
?>
+ 0
?? Which of the following functions is not used in debugging?
+ fprintf()
?? Which of the following cryptographic functions in PHP returns the longest hash value?
+ sha1()
?? Consider the following class:
1 class Insurance
2 {
3 function clsName()
4 {
5 echo get_class($this);
6 }
7 }
8 $cl = new Insurance();
9 $cl->clsName();
10 Insurance::clsName();
Which of the following lines should be commented to print the class name without errors?
+ Line 9 and 10
?? Without introducing a non-class member variable, which of the following can be used to keep an eye on the existing number of objects of a given class?
+ Adding a member variable that gets incremented in the default constructor and decremented in the destructor
?? Which of these is not a valid PHP XML API?
+ b.libXMLError()
?? Which of the following is not a valid API?
+ trigger_print_error()
?? Which of the following is true about posting data using cURL in PHP?
+ Data can be posted using both GET and POST methods
?? Which of the following is the correct way to check if a session has already been started?
+ if ($_SESSION[«session_id»]) echo ‘session started’
?? Which statement will return true?
Note: There may be more than one right answer
+ a. is_numeric («200»)
?? Which of the the following are PHP file upload-related functions?
+ is_uploaded_file()
?? Which of the following statements regarding PHP forms, are correct?
Note: There may be more than one right answer
+ In PHP, the predefined $_POST variable is used to collect values in a form with method=»post».
+ In PHP, the predefined $_GET variable is used to collect values in a form with method=»get».
?? grabage
+ gc_cycles()
__________________________________________________________________
?? Which MIME type needs to be used to send an attachment in mail?
+ multipart/mixed
?? What is the output of the following code?
class Foo {
private $foo;
protected $bar;
public $test;
public function __construct()
{
$this->foo = 1;
$this->bar = 2;
$this ->test = 3;
}
}
print_r( (array) new Foo );
+ Array([Foofoo]=>1 [*bar]=>2[test]=>3)
?? By default, every database connection opened by a script is either explicitly closed by the user during run time of released__________ at the end of the script.
+ Server-side
?? Which magic method is used to implement overloading in PHP ?
+ __call
?? What will be the output of following code ?
<?php $i = 016;echo $i /2; ?>
+ 7
?? Which of the following file modes is used to write into a file at the end of the existing content, and create the file if the file does not exist?
+ a
?? Which of the following statements is incorrect with respect to inheritance in PHP?
+ A Class can extend more than one class.
?? You can extend the exception class, but you cannot override any of the preceding methods they are declared as:
+ final
?? What is the correct syntax of mail() function in php ?
+ mail($to,$subject,$message,$headers)
?? What is the fastest way to insert an item $item into the specified position $position of the array $array ?
+ array_merge() and array_slice()
?? Which of the following MySQL fetch constants imply: if the columns are returned into the array having both a numerical index and the field name as the array index ?
+ Ans. MYSQL_BOTH
?? Which function is used to get the number of arguments passed to the function ?
+ func_num_args()
?? What is the output of the following code ?
<?php
function abc(){
return_FUNCTION_;
}
function xyz(){
return abc();
}
echo xyz();
?>
+ abc
?? Which Function can be used to determine if a file exist? (choose all that apply)
+ is_readable()
+ file_exists()
+ is_file_exists()
?? What will be the output of following code
<?php
class A {
public static function foo() {
static::who();
}
public static function who(){
echo __CLASS__.”\n”;
}
}
class B extends A {
public static function test(){
A::foo();
parent::foo();
self::foo();
}
public static function who() {
echo __CLASS__. “\n”;
}
}
Class C extends B {
public static function who(){
echo __CLASS__.”\n”;
}
}
C::test();
?>
+ ACC
?? Which of the following will print out the PHP call stack ?
+ $e=new Exception;
var_dump($e->getTraceAsString())
?? What is the correct way to send an SMTP(Simple Mail Transfer Protocol) email using PHP?
+ sendmail($EmailAddress,”Subject”,”$MessageBody);
?? The PDO_MYSQL Data Source Name(DSN) is composed of the following elements ?
+ dbname
+ unix_socket
+ charset
?? Which is true about the curl_setopt() API ?
+ It sets one option for cURL transfer
?? What will be the output of the following PHP code ?
<?php
$var=300;
$int options = array(“options”=>array(“min_range”=>0,”max_range”=>256));
if(!filter_var($var,FILTER_VALIDATE_INT, $int_options))
echo(“Integer is not valid”);
else
echo(“Integer is valid”);
?>
+ Integer is not valid
?? Which function is used to read a file removing the HTML and PHP tags in it ?
+ fgetss()
?? What will the output of following code :-
<?php
class BaseClass {
public function test() {
echo “BaseClass::test() called\n”;
}
final public function moreTesting() {
echo “BaseClass::moreTesting() called \n”;
}
}
class ChildClass extends BaseClass {
public function moretesting(){
echo “ChildClass::moreTesting() called\n”;
}
}
$obj = new ChildClass;
$obj->moreTesting();
?>
+ Results in Fatal error : Cannot override final method
BaseClass::moreTesting();
?? What will happen if a fatal error was thrown in your PHP program ?
+ The PHP program will stop executing at the point where the error occured.
?? Which of the following code can be used to send email to multiple recipients ?
+ $recipients = array(‘recipient1@domain.com’,’receipient2@domain.com);
mail($recipients,$subject,$messege,$headers);
?? Which of the following functions belong to Exception class ? (Choose all that apply)
+ getLine()
+ getTraceAsString();
?? Which of the following are valid MySQLi Configuration options ? (Choose all that apply ?
+ mysqli.allow_persistent
+ mysqli.default_port
+ mysqli.default_socket
?? Which is the best approach to parse HTML and extract structured information from it ?
+ Use an XML parser (as simpleXML) and XPath queries if available.
?? What is the output of the following code ?
<?php
function y($v) {
echo $v;
}
$w = “y”;
$w (“z”);
$w = “x”;
?>
+ z
?? Xdebug is a PHP____________, the information which Xdebug provides is about stack and functions with full parameter for user defined functions, memory allocation and support for infinite recursions.
+ Extension
?? See the example class code below
class ExampleClass{
public $val = 5 ;
function &getValNum()
{
return $this->val;
}
}
which of the following one can be used for Return by reference ?
+ $obj = new ExampleClass();
+ $myVal = $obj->getValNum();
?? What is the output of following code ?
function myFun($a) {if(!$a){
throw new Exception(‘Value init.’);
}
return 3/$a;
}
try {
echo myfun(3) .”\n”;
} catch (Exception $e){
echo ‘Caught exception: ‘, $e->getMessage(), “\n”;
} finally {
echo “first\n”;
}
try{
echo myFun(1).”\n”;
} catch (Exception $e) {
echo ‘Caught exeption:’, $e->getMessage(),”\n”;
} finally {
echo “second\n”;
}
echo “Hello PHP Example\n”;
+ 1 first 3 second Hello PHP Example
?? What is true about ini_set(‘memory_limit’,’-1’) ?
+ parse error
?? what is the correct way to read-in multiple values from an array ?
+ list($x,$y,$z) = array(7,8,9);
?? What is the best practice for running MySQL queries in PHP? Consider the risk of SQL injection ?
+ Use PDO prepared statements and parameterized queries
?? Which of the following is the right MIME to use as a Contant Type for JSON data ?
+ application/json
?? Which of the following is the correct way to convert a variable from a string to an integer ?
+ $number_variable = (int)$string_variable;
?? There are a number of mysqlnd plugins already available. These include
+ PECL/mysqlnd_pscache – Prepared Statement Handle Cache plugin
+ PECL/mysqlnd_sip – SQL Injection Protection Plugin
+ PECL /mysqlnd_uh – User Handler Plugin
+ PECL/mysqlnd_qc – Query Cache Plugin
?? What will be the output of executing the following code ?
+ Fata error : Call to private method Foo:: printName() from context
?? When designing classes with UML, a class at its core has the following components ? (choose all that apply)
+ Methods, Attributes
?? Which of the following would show an error in php ?
+ @echo 1
?? What would be the output of the following code ? $str = “0011110000bsts11100”;echo trim($str,’010s’);
+ bst
?? What would be the output of the I and II sample codes:
I)$a = array();
$b = $a;
$b[‘foo’] = 42;
echo $a[‘foo’];
II)
$a = new StdClass();
$b = $a;
$b->foo = 42;
echo $a->foo;
+ Null 42
?? Which of the following is not a Super Global variable in PHP ?
+ None of the above
?? Which of the following would produce an error :
$currentDT = new DateTime();
+ $currentDT->getTimezone(new DateTimeZone(‘UTC’));
?? Which statement is incorrect ?
+ unset() forces the PHP garbage collector to immediately.
?? following file modes is used to srite into a file at the end
+ a
?? which of the following is not related to garbage collection in PHP ?
+ gc_cycles()
?? which statement is not correct ? $x = null;
+ empty($x) return TRUE
?? What would be the output of the following code ?
$parts = parse_url(“https://example.com/test/1234?testing&val&id=1&&=23&row=4”);
parse_str($parts[‘query’],$query);
echo count($query);
+ 4
?? Which of the following is not the correct way to create an empty object in PHP ?
+ $obj = new stdClass();
?? Which function is used to destroy a variable or object ?
+ unset()
?? What will be the output of the following code ?
$arr = array(“THEY”,”WE”,array(“I”,”YOU”),”YOUR”);
echo(count($arr,1));
+ 6
?? Which statement is not correct ?
+ PHP_EOL – The correct ‘End of Line’ symbol for this platform
?? Which method is used to tweak an oject’s cloning behavior ?
+ __clone()
?? How do you access result set meta data ?
++++++++++++++++++++++++++++++
<?php
$mysqli = new mysqli(“example.com”, “user”, “password”, “database”);
if ($mysqli->connect_errno) {
echo “Failed to connect to MySQL: (” . $mysqli->connect_errno . “) ” . $mysqli->connect_error;
}
$res = $mysqli->query(“SELECT 1 AS _one, ‘Hello’ AS _two FROM DUAL”);
var_dump($res->fetch_fields());
?>
++++++++++++++++++++++++++++++
?? Which of the following will decode a JSON variable $json to an object ?
$json = ‘{“abc”:1,”def”:2,”ghi”:3,”jkl”:4,”mno”:5}’;
+ both of above ($object = json_decode($json); and $object = json_decode($json,true);)
?? Choose the correct option to force redirect from http to https :
+ RewriteCond %{HTTPS} off
+ RewriteRule (.*) https://%{HTTP_HOST}%{REQUEST_URI}
?? What will be the output of executing the following code ?
<?php
class Foo {
private function printName($name) {
print_r($name);
}
}
$a = new Foo();
$a->printName(‘James’);
?>
+ Fatal error: Call to private method Foo::printName() from context…
?? What will be the output of the below code ?
$tmp = “Dragon%%Ball%%z%”;
$arr = explode(‘%’,trim($tmp));
echo count($arr);
+ 6
?? Which of the following options will fall to remove the element “y” when placed in the blank space in the below sample code
$row = array(0=>”x”,1=>”y”,2=>”z”,3=>”w”)
print_r($row)
+ array_diff($row,[“y”]);
?? Which of the following is the correct option to get a numerically indexed array containing all defined timezone identifiers in PHP
+ DateTimeZone::listIdentifiers(DateTimeZone::UTC);
?? What will be the output of the following code ?
echo(1234==’1234 test’ ? ‘Equal’ : ‘Not equal’);
+ Equal
?? After the following query is executed using PHP, which function can be used to count the number of rows returned ?(choose all that apply)
SELECT * from students
+ mysqli_affected_rows()
+ mysqli_numrows()
?? enums
+ Enum cennot create in PHP
?? POSIX
+ ereg_replace
+ ereg
+ eregi
+ eregi
+ split
+ spliti
+ sql_regcase
?? Where can protected property or method be access?
+ It can only be accessed within the class itself or in descendant classes
?? $var1
+ Not found
?? With regards to the "static" keyword in PHP? which of the following statements is false?
+ The $this variable can be used inside any static method
- Static properties may only be initialized using a literal or a constant
- A property declared as static can not be accessed with an instantiated class object
- A static variable or method can be accessed without requiring instantiation of the class
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment