How does Casting work in PHP?

What does not work:

(int)08 == (int)09==0

But is that so?

(int)07==7 
(int)06==6 
+3
source share
6 answers

08 is in octal base (because it starts with 0), so it is not valid. See the documentation .

+14
source

because 08and 09are not valid octal numbers. see warning in docs .

+11
source

.

+1
// Syntax error
//(int)08 == (int)09==0

// This works
(int)08==0;
(int)09==0;

// This also works
(int)08 == ((int)09==0);
0

(int)

intval().

0

0x.

,

 $num = (int)0x9
 $num == 9
-1

Source: https://habr.com/ru/post/1724950/


All Articles