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?

base class,constructor,call,parent class,PHP, Question, call constructor from parent,PHP: Calling Parent Class Constructors,class Parent
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
       }
}






Bookmark and Share

How do I find out the number of parameters passed into function?

PHP: func_num_args - Manual,PHP: Function arguments - Manual,PHP: func_get_args - Manual,PHP,Quesion
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");
?>




Bookmark and Share

Ternary conditional operator in PHP?

Ternary conditional operator, PHP, Question, conditional operator,ternary operator,explode php,php implode
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;
?>


Bookmark and Share

Will comparison of string and integer work in PHP?

PHP, PHP: Comparison Operators - Manual, Question
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.


Bookmark and Share

How do you define a constant?

PHP, PHP constant() Function, PHP: Constant - Manual, PHP: Constants - Manual, PHP: define - Manual, Question, how do you define a constant
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:

<?php
//define a constant
define("Test","Hello Rajesh Sharma! How are you today?");


echo constant("Test");
?>




Bookmark and Share

PHP Interpreter in php?

I am trying to assign a variable the value of 0123, but it keeps coming up with a different number, what’s the problem?


Ans:- PHP Interpreter treats numbers beginning with 0 as octal.

















Bookmark and Share