Showing posts with label OOP interview questions and answers. Show all posts
Showing posts with label OOP interview questions and answers. Show all posts
How do you call a constructor for a parent class?
Posted by Raj
How do you call a constructor for a parent class?
parent::constructor($value)
Example:
class parentClass
{
function __construct()
{
}
}
class chClass extends parentClass
{
function __construct()
{
parent::__construct(); //call a constructor for a parent class
}
}
How do I find out the number of parameters passed into function?
Posted by Raj
How do I find out the number of parameters passed into function?
func_num_args — Returns the number of arguments passed to the function.
Example:
<?php
function test()
{
$number_of_args = func_num_args();
echo "Number of arguments: $number_of_args";
}
test ("a","b");
?>
Ternary conditional operator in PHP?
Posted by Raj
Ternary conditional operator:
Expression preceding the ? is evaluated, if it’s true, then the expression preceding the : is executed, otherwise, the expression following : is executed.
Syntax:
Condition ? value if true :value if false;
Example:
<?php
$id = isset($_POST['name']) ? $_POST['name'] : false;
?>
Will comparison of string and integer work in PHP?
Posted by Raj
Yes you can compare string and integer in PHP as internally PHP will cast everything to the integer type, so numbers 100 and 100 will be compared.
How do you define a constant?
Posted by Raj
In this section, I will explain how to define a constant in PHP.
define("Test","Hello Rajesh Sharma! How are you today?");
The constant() function returns the value of a constant.
Syntax:
constant(constant);
Example:
//define a constant
define("Test","Hello Rajesh Sharma! How are you today?");
echo constant("Test");
?>
PHP Interpreter in php?
Posted by Raj
Ans:- PHP Interpreter treats numbers beginning with 0 as octal.