php - I encountered a syntax problem late at night and was speechless.
为情所困
为情所困 2017-05-16 13:02:31
0
2
287

< /p>



const Administration = 0x1 << 1;

The code is this sentence. It uses const to define a constant, and only uses the displacement symbol in the constant. There is no problem in the win system, but a syntax error is reported in the ubuntu system!
为情所困
为情所困

reply all(2)
伊谢尔伦

This is not a problem with PHP, but nine times out of ten it is a problem with your editor.

<?php

class Privilege{
        const Administration = 0x1 << 1;
}

$a = new Privilege();
echo $a::Administration;

On centos and mac (both are php7), the output results are both 2, no problem

php version problem.

changelog is here:

http://php.net/manual/zh/migr...

New features introduced in 5.6:

Use expressions to define constants

In previous PHP versions, static values ​​had to be used to define constants, declare properties, and specify default values ​​for function parameters. You can now use numeric expressions including numbers, string literals, and other constants to define constants, declare properties, and set default values ​​for function parameters.

Before 5.6, static values ​​must be used. After 5.6, constants can be defined using operations

迷茫

Personally, I think the reason for this error is that the online PHP version is lower than 5.6. Before PHP5.6, the rvalue of a constant could only be a direct quantity and a static value, not an expression. Only starting from PHP 5.6, expressions are supported as rvalues ​​of constants.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template