PHP Interview questions


Total available count: 33
Subject - PHP Frameworks
Subsubject - PHP

What are Objects?

To create instance of a class, a new keyword must be used. An object will always be created unless the object has a constructor. It throws an exception on error. Classes should be defined before instantiation (and in some cases this is a requirement).

If a string contains the name of a class is used with new, a new instance of that class will be created. If the class is in a namespace, its fully qualified name must be used when doing this.

Example: 

<?php
$instance = new Slightbook();

// This can also be done with a variable:
$className1 = 'Slightbook';
$instance = new $className1(); // new Slightbook()
?>

In a class context, it is possible to create a new object by new self and new parent.

When assigning an already created instance of a class to a new variable, the new variable will access the same instance as the object which was assigned. This behaviour is the same when passing instances to a function. A copy of already created object can be made by cloning it.




Next 5 interview question(s)

1
What are Classes?
2
What is an operator and how many types of operators are there?
3
What is the difference between named functions vs anonymous functions?
4
What is the difference between var_dump() vs print_r()?
5
What is the use of var_dump() function?