Special Operators in PHP

Notes:

PHP Special Operators

new operator:
- is used to create new instance of a class
Syntax:
$variableName = new ClassName();

instanceof operator:
- is used to test whether a variable is pointing to an instance of a specific class
Syntax:
$variableName instanceof ClassName

member access operator (->):
- is used to access members of an object
Syntax:
$variableName->memberName

scope resolution operator(::):
- is used to access static, constant & overridden members of a class
Syntax:
$variableName::memberName
OR
ClassName::memberName

Example Code:
class Circle
{
var $radius = 10;
const PI=3.142;
}
$circle1 = new Circle();
echo $circle1 instanceof Circle ? "true" : "false"; // true
echo "<br/>";
echo $circle1->radius; // 10
echo "<br/>";
echo Circle::PI; // or $circle1::PI; // 3.142
echo "<br/>";

Interview Questions:

1. PHP stands for ______________
a. Hypertext Preprocessor
b. Preprocessor Hypertext
c. Personal Home Processor
d. Personal Hypertext processor
Ans: a