我正在使用CBOR在我的C应用程序和PHP脚本中打包数据。对于PHP,我已经从上面的网站下载了实现。它在 PHP 5.4.23 中运行良好,但在包含 CBOREncoder 的 PHP 5.3.3 上.php会产生错误:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /var/www/html1/......./CBOREncoder.php on line 15
这是 CBOREncoder.php 的开始:
<?php
/**
* CBOR encoder/decoder
*
* http://tools.ietf.org/html/rfc7049
* http://habrahabr.ru/post/208690/ thx man :)
*
* Class CBOREncoder
*/
class CBOREncoder
{
const
MAJOR_OFFSET = 5,
HEADER_WIPE = 0b00011111, <-- this line produces error
ADDITIONAL_WIPE = 0b11100000,
怎么了?
问题是 PHP 5.3.x 不支持二进制数。这包含在 PHP 5.4 中。
来自php网站: http://php.net/manual/en/migration54.new-features.php
添加了二进制数格式,例如 0b001001101。
所以,CBOR 不支持 PHP 5.3