Declaring a variable in PHP and issue with # error suppression [duplicate] - php

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 3 months ago.
what does the following codeline do?
$this->wordData[$wordCount] = ((#$this->wordData[$wordCount] << $remainingBit) | ($bufferVal >> $bufferBit));
It's a snippet of qrcode of mpdf (line 444). since PHP 8 it throws PHP Warning: Undefined array key 43 for example.
I know # is PHP error-suppression, but since PHP 8 it is working another way as it does before PHP 8.
The part after the "=" --> ((variable << variable) | variable) is that a kind of if than (with | for OR)? I'm confused ;-)
I am teaching myself PHP and would therefore be glad if someone could help me with an explanation for beginners.
Thanks
Andreas

There have been some changes in error suppression in PHP8 - see https://php.watch/versions/8.0/fatal-error-suppression
Note that the << and >> are bitwise operators to shift the bits of a number left or right, respectively. See https://www.php.net/manual/en/language.operators.bitwise.php

Related

PHP numbers logic [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
What does the percent sign mean in PHP?
(6 answers)
Closed 3 years ago.
I just started to learn PHP deeper for Zend PHP certification and I found this code, which actually works. Can someone explain me the logic behind this?
<?php
$num = 20% - 8;
echo $num; // 4
What you're seeing is the modulus operator, which in essence asks "What is the remainder of 20 divided by -8".
So you might ask, why isn't it negative 4? From the manual,
The result of the modulo operator % has the same sign as the dividend — that is, the result of $a % $b will have the same sign as $a.
See the PHP: Arithmetic Operators for more documentation.
% is not per cent, but modulus, cf. https://en.m.wikipedia.org/wiki/Modular_arithmetic
20 = 2 * 8 + 4, therefore, 20 % 8 = 4

What is the meaning of this symbol ">>" in PHP [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 7 years ago.
I found this example and i can't understand the result :
$x = 5;
echo $x>>2;
output :
1
Can you explained for me please
Thanks
$a >> $b Shift right Shift the bits of $a $b steps to the right (each step means "divide by two")
So if 5 in binary is: 101
5>>1 is 2 in binary 10
5>>2 is 1 in binary 1
This operator if common in other languages such as C.
Source

What does a single ampersand mean in a PHP conditional statement? [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Closed 8 years ago.
The following code uses a single & in a conditional check. What does the single ampersand mean there?
if( $some_array_or_other_var & SOME_CONSTANT_VARIABLE ){
//do something here
}
It does not look like a reference, that's what confuses me.
That is a bitwise AND operation: http://www.php.net/manual/en/language.operators.bitwise.php
If, after the bitwise AND, the result is "truthy", the clause will be satisfied.
For example:
3 & 2 == 2 // because, in base 2, 3 is 011 and 2 is 010
4 & 1 == 0 // because, in base 2, 4 is 100 and 1 is 001
This is commonly used to check a single bit in a bitset, by testing powers of two, you are actually checking if a specific bit is set.

What does `<<` mean when declaring a variable in PHP? [duplicate]

This question already has answers here:
Reference Guide: What does this symbol mean in PHP? (PHP Syntax)
(24 answers)
Strange print behaviour in PHP? [duplicate]
(2 answers)
Closed 10 years ago.
I was looking at this article about facebook's HipHop Virtual Machine (HHVM) when I noticed this line:
<?php
$u_bytes =
$p_bytes = 100 << 20;
I tested it by running echo 100 << 20; and the value was 104857600. What does << 20 do?
Edit
Based on the answers it's a bitwise operator (bit shift [left]). Example:
100 = 000000000000000000001100100
^ `<< 20` moves this bit 20 bits to the left
104857600 = 110010000000000000000000000
This is a bit shift left.
You can learn more on how it works in PHP directly on PHP Manual: http://php.net/manual/en/language.operators.bitwise.php

What does this PHP syntax mean [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Reference - What does this symbol mean in PHP?
Can someone tell me what's the << 0 for? and other more common alternatives if they exist
$newvalue += 1 << 0;
<< is the bitwise left-shift operator.
In this case is seems pretty pointless, since left-shifting 1 by 0 equals 1.
<< 0 does nothing. It is probably there to indicate that the value is some sort of flag. If it was something other than 0, than it would shift the value (1) left by x bits, where is is the value replacing 0.

Categories