Operators Flashcards
What are the non-associative operators?
clone
new
instanceof
»
= == === != !==
What are the right associative operators?
**
!
++ – ~ (int) (float) (string) (array) (object) (bool) @
= += -= *= **= /= .= %= &= |= ^= >= =>
All of the others are either non-associative or left associative.
What is the ** operator?
Exponentiation.
2 ** 3 = 8
What does the division operator return?
The division operator (“/”) returns a float value unless the two operands are integers (or strings that get converted to integers) and the numbers are evenly divisible, in which case an integer value will be returned.
How are modulus operands handled?
Operands of modulus are converted to integers (by stripping the decimal part) before processing.
What is the sign of the result of a modulus operator?
The result of the modulus operator % has the same sign as the dividend — that is, the result of $a % $b will have the same sign as $a.
What is the value of $a = 3?
3
The value of an assignment operator is the value assigned.
Are objects assigned by value or reference?
Reference. However, they may be explicitly copied using the ‘clone’ keyword.
Are objects assigned by value or reference?
Reference. However, they may be explicitly copied using the ‘clone’ keyword.
What happens when you assign the result of new by reference, like this:
class C{} $o = &new C;
It results in an E_DEPRECATED error message, because the new operator returns a reference automatically.
What happens when you assign the result of new by reference, like this:
class C{} $o = &new C;
It results in an E_DEPRECATED error message, because the new operator returns a reference automatically.
What are these bitwise operators?
$a & $b $a | $b $a ^ $b ~ $a $a > $b
$a & $b And Bits that are set in both $a and $b are set.
$a | $b Or (inclusive or) Bits that are set in either $a or $b are set.
$a ^ $b Xor (exclusive or) Bits that are set in $a or $b but not both are set.
~ $a Not Bits that are set in $a are not set, and vice versa.
$a > $b Shift right Shift the bits of $a $b steps to the right (each step means “divide by two”)
What happens to bits shifted off either end with bitwise operators?
They are discarded. Left shifts have zeros shifted in on the right while the sign bit is shifted out on the left, meaning the sign of an operand is not preserved. Right shifts have copies of the sign bit shifted in on the left, meaning the sign of an operand is preserved.
What happens if both operands for the &, | and ^ operators are strings?
The operation will be performed on the ASCII values of the characters that make up the strings and the result will be a string. In all other cases, both operands will be converted to integers and the result will be an integer.
What happens if both operands for the &, | and ^ operators are strings?
The operation will be performed on the ASCII values of the characters that make up the strings and the result will be a string. In all other cases, both operands will be converted to integers and the result will be an integer.
What happens if the operand for the ~ operator is a string?
The operation will be performed on the ASCII values of the characters that make up the string and the result will be a string, otherwise the operand and the result will be treated as integers.
How are operands and the result for»_space; and
They are always treated as integers.
What happens when you shift integers by values greater than or equal to the system long integer width?
It results in undefined behavior.
What is the operator?
Not equal. Same as: !
What are the === and !== operators?
Identical (equal and of the same type) and not identical.
What is the “” operator?
Spaceship operator.
0 if $a and $b are equal, 1 if $a is greater than $b, -1 if $b is greater than $a.
What happens if you compare a number with a string or the comparison involves numerical strings?
Each string is converted to a number, and the comparison is performed numerically. These rules also apply to the switch statement.