I am using CBOR for packing data in my C applications and PHP scripts. For PHP, I've downloaded implementation from the site above. It works good at PHP 5.4.23, but on PHP 5.3.3 including CBOREncoder.php produces an error:
Parse error: syntax error, unexpected T_STRING, expecting ',' or ';' in /var/www/html1/......./CBOREncoder.php on line 15
This is beginning of 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,
What's the problem?
The problem is PHP 5.3.x does not support binary numbers. That was included in PHP 5.4.
From php website: http://php.net/manual/en/migration54.new-features.php
Binary number format has been added, e.g. 0b001001101.
So, CBOR does not support PHP 5.3
Related
In an include file I declare a function
function patch_163_output_row_header(
string $title,
string $label,
$help,
bool $read_only=false,
bool $required=false,
string $label_cell
)
and when I compile this using the XAMPP PHP compiler (8.1.6 as far as I can tell) it is OK
In another file I try to use the function
patch_163_output_row_header(
title:$title,
label:$label,
help:$help,
read_only:$read_only,
required:$required,
label_cell:$label_cell
);
when I try to compile I get the error mentioned above on the"title" line.
I can see no obvious issues - title does not seem to be a reserved word?
The strange thing then is that these two files are part of a website and when they are executed by the same XAMPP stack (presumably using the same PHP compiler?) there are no errors reported and they work.
I have get following error in my Laravel Application.
Turns out that the error points to the following lines:
/* August */
$augledcrdt=Companyledger::WhereIn('frm_ledger',$ledgerlist)->whereYear('transaction_date',$curyear)->whereMonth('transaction_date',08)->where('company_id',$companyids)->sum('credit_amt');
$augleddebt=Companyledger::WhereIn('frm_ledger',$ledgerlist)->whereYear('transaction_date',$curyear)->whereMonth('transaction_date',08)->where('company_id',$companyids)->sum('debit_amt');
/* September */
$sepledcrdt=Companyledger::WhereIn('frm_ledger',$ledgerlist)->whereYear('transaction_date',$curyear)->whereMonth('transaction_date',09)->where('company_id',$companyids)->sum('credit_amt');
$sepleddebt=Companyledger::WhereIn('frm_ledger',$ledgerlist)->whereYear('transaction_date',$curyear)->whereMonth('transaction_date',09)->where('company_id',$companyids)->sum('debit_amt');
I think you are using PHP 7.0. You can use the following piece of code to do so:
$augledcrdt=Companyledger::WhereIn('frm_ledger',$ledgerlist)->whereYear('transaction_date',$curyear)->whereMonth('transaction_date','08')->where('company_id',$companyids)->sum('credit_amt');
$augleddebt=Companyledger::WhereIn('frm_ledger',$ledgerlist)->whereYear('transaction_date',$curyear)->whereMonth('transaction_date','08')->where('company_id',$companyids)->sum('debit_amt');
You should change 08 to 8 if you're using PHP7:
->whereMonth('transaction_date', 8)
http://php.net/manual/en/migration70.incompatible.php#migration70.incompatible.integers
I have recently put up a server, and I am making changes gradually. One of the changes is the contents of a php page. I commonly use a php "shell" (just a textarea and the php just evals what is written). I have made some changes and want to use
fwrite($file, "<?php php here ?>");
but i am getting an error. I believe I know the problem, and it is because i have nested php like
<?php
$a = fopen('../php.php', 'w');
fwrite($a, "
<?php
eval($_POST['phptorun']);
?>
");
fclose($a);
?>
Is there any way I can get it to just put that php code into the file php.php?
The error i was getting is:
Parse error: syntax error, unexpected '' (T_ENCAPSED_AND_WHITESPACE), expecting identifier (T_STRING) or variable (T_VARIABLE) or number (T_NUM_STRING) in /var/www/html/Tyler/replace.php on line 5
Edit:
I forgot to say a couple of things. The server is a LAMP (Linux Apache MySQL PHP), running on my Raspberry Pi 2, model B. If you want to visit my server, it is at 71.204.114.18
Try to escape the $ symbol:
<?php
$a = fopen('../php.php', 'w');
fwrite($a, "
<?php
eval(\$_POST['phptorun']);
?>
");
fclose($a);
?>
My script is working really fine on my xampp php version 5.6. Now I tried to upload it on the server php version 5.3.3 , it says
PHP Parse error: syntax error, unexpected '['
The line which its mocking about is this one:
$this->pending_nodes[$number] = [];
The whole code block looks like this:
public function addPendingNode(ProtocolNode $node){
$from = $node->getAttribute("from");
if(strpos($from,Constants::WHATSAPP_SERVER) !== false)
$number = ExtractNumber($node->getAttribute("from"));
else
$number = ExtractNumber($node->getAttribute("participant"));
if(!isset($this->pending_nodes[$number]))
$this->pending_nodes[$number] = [];
$this->pending_nodes[$number][] = $node;
}
I am thankful for any help, I cannot seach [ with google and have no idea where it could come from, since on xampp its working fine.
Short Array syntax was introduced in PHP 5.4 only.
Change
$this->pending_nodes[$number] = [];
to
$this->pending_nodes[$number] = array();
or upgrade to a PHP version that is not End of Life.
E.G.
if(!isset($am_states[$lot.'_-40C'])){
or
$am_states[$temp."_".$states[$i]['temperature']] = $states[$i]['temperature'];
Whenever I have arrays with concatenated string as array-keys php returns an error:
Parse error: syntax error, unexpected '.', expecting ']'
So I am assuming something is wrong with the server configuration although I am sure i changed something on my local configuration.
Last time i changed the configuration was when i setup my apache/mysql/php installation
that is PHP Version 5.3.1,Apache/2.2.14,MYSQL5.1.41 (default from xampp1.7.3)
so I was using this syntaxes 7 months ago and they were working properly. It just now that they produce errors.
Anyone can help?
Are you positive about the PHP version you're using? The following test (using PHP 5.3.6 (cli)) works without issue. Perhaps you could post a more complete example?
#!/usr/bin/env php
<?php
$states = array(
array('temperature' => 40),
array('temperature' => 50),
array('temperature' => 60)
);
$temp = 'test';
$i = 2;
$am_states[$temp . "_" . $states[$i]['temperature']] = $states[$i]['temperature'];
var_dump($am_states);
The output of this script is:
array(1) {
["test_60"]=>
int(60)
}