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.
Related
This question already has answers here:
Incorrect syntax near 'GO'
(9 answers)
Closed 6 years ago.
I am having trouble executing a long MSSQL script using PHP and PDO.
It contains some batch statements separated by GO. The script runs if its executed in Management Studio.
I have ensured line endings are not causing the issue.
I have also tried to enable beginTransaction() before the request is executed. Which returns the following error: SQLSTATE[IMSSP]: This function is not implemented by this driver.
I'm using IIS8 and PHP 5.4.16 and the pdo_sqlsrv driver
First part of the script:
USE foo;
IF object_id(N'ToBit', N'FN') IS NOT NULL
DROP Function dbo.ToBit
GO
CREATE FUNCTION dbo.ToBit(
#InputString varchar(250)
)
RETURNS BIT
AS BEGIN
DECLARE #OutputBit BIT
SET #OutputBit = CASE
WHEN (#InputString = 'yes') THEN 1
WHEN (#InputString = 'true') THEN 1
WHEN (#InputString = '1') THEN 1
ELSE 0
END
RETURN #OutputBit
END
Is it down to the driver? I can't see why GO would require beginTransaction() being called? Other than that I'm out of ideas.
Update: I think I might have found an answer here. Will update if I find a soloutio.
Incorrect syntax near 'GO'
Have found an answer here by Jon Galloway
GO isnt valid T-SQL, its a command used by SQLCMD and other utilities, and parsed before execution.
It looks like there are a few options.
1) Execute the script using OSQL / command line
2) Split the script at each GO separator, then run them in sequence
3) If using .NET you can look at using SQL Server Management Objects:
Server.ConnectionContext.ExecuteNonQuery()
This parsers T-SQL statements and "gets" the GO statement as a batch separator.
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
I'm working with NetBeans for Mac, and I'm running CakePHP (though I don't think the framework has anything to do with it) in a shared hosting in Linux. This is not a big issue, but it is frustrating.
I wonder why I can't simply do this:
if($this->Session->read('User.value1') || $this->Session->read('User.value2')){
...
}
The error message I get is:
Error: syntax error, unexpected '$this' (T_VARIABLE)
Why is there a syntax error? I can't see it.
I can do this with no problems:
if($this->Session->read('value1')){
...
}
I can also do this with no problems (no whitespace around ||):
if($this->Session->read('User.value1')||$this->Session->read('User.value2')){
...
}
But if I put spaces around the || operator, it stops working. Or rather — and this is the most confusing part — sometimes it stops working when I put spaces around the || operator, and sometimes it doesn't.
I thought this might be a bug in Netbeans 7.4, but when I ignored the warning from NetBeans and tried to run the code anyway, PHP gave me the same error.
What is happening here?
I'm working With NetBeans for MAC
When is a space not a space?
When it's a non-breaking space!
The intention is:
" || "
207C7C20 (hex)
But what is actually in the source file is almost certainly:
" || "
207C7CA0 (hex)
(on stack overflow it won't be but I bet it is in the source file).
With a mac the problem is (using my own keyboard layout, but I am assuming it's similar in your case):
"|" = alt + 1
" " = alt + space (accidental)
So typing away, with the sequence " || " it's very easy for the alt key to still be depressed when the space bar is pressed and: voilà you get unexpected "wat" syntax errors which at face value make no sense - until you realize what the problem is.
Example:
-> cat foo.php
<?php
$foo = "x";
if (true || $foo) {
}
-> php -l foo.php
Parse error: syntax error, unexpected '$foo' (T_VARIABLE) in foo.php on line 4
Errors parsing foo.php
I was troubleshooting some code and I took it out of the execution path so that I could look in other places.
PHP continued to call out the code as an error despite it not being executed. It is in a function that is not called.
Is this expected behavior?
// not in execution path
$temp1 = $this->hash;
$temp = array('1', $temp1); // this is line 121
$this->database_object->_pdoQuery('none', 'update_picture', $temp );
syntax error, unexpected T_LNUMBER, expecting ']' in
/home/foo/public_html/dev/foo/source/class.MAppPicture.php
on line 121
The entire file has to be parsed prior at the time of access or include. This is generating an error because it is a parse time error and php can't understand the file as a whole because of the syntax error.
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)
}