I'm really baffled by an issue of running a small PHP application on Windows using the CLI (5.6).
I am simply running my app with:
bin\php -f sync.php
What I get is a syntax error issued out of an include'd file. The bizarre thing is, it appears that PHP is actually truncating my included script during processing. I know this because if I remove some of that scripts content (reducing total bytes), I can eventually get it to process without error.
Other relevant information:
Running PHP 5.6
Running on a Windows 7 VM
Application function is to connect to a SQLLocalDb instance
PHP sqlsrv driver is installed
Errors are thrown when included script exceeds ~633 bytes
I have tried to switch both encoding and line endings to remedy without success
If you think the error output is relevant, here you go:
PHP Warning: Unexpected character in input: ' in S:\config.php on line 27
Warning: Unexpected character in input: ' in S:\config.php on line 27
PHP Parse error: syntax error, unexpected end of file in S:\config.php on line
27
Parse error: syntax error, unexpected end of file in S:\config.php on line 27
If I eliminate some characters from that script while keeping valid syntax, it will execute without error. Any thoughts as to the cause?
Edit: It turns out that something may be wrong with the format of my included script. So I'm posting it for context. Maybe it's been that long since I've worked on Windows, that I am forgetting some bizarre rule about PHP syntax:
<?php
/**
* Configuration settings.
*
* PHP Version 5
*
* #category Configuration
* #author XXXXXX XXXXXXXX
* #copyright 2016 XXXXXX XXXXXXXX, XXX. All Rights Reserved.
*/
$config = array(
'magento' => array(
'wsdl' => 'http://redacted-url-still-filling-needed-size/api/v2_soap/?wsdl=1',
'username' => 'user',
'password' => 'pass',
),
'last_sync' => '2016-09-01 00:00:00',
'db' => array(
'adapter' => 'app_db_sqlsrv',
'host' => 'localdbt',
'name' => 'dbname',
'username' => 'root',
'password' => 'password',
),
);
Related
I'm following the codecourse video series Authentication with Slim 3, which is about 3 years old.
I've hit a snag when it comes to using eloquent to access a mysql database.
(the relevant video: https://www.youtube.com/watch?v=70IkLMkPyPs )
the code wasn't quite the same as that currently recommended on the instructions on illuminate/database's docs, so I've modified the code slightly to follow that standard, but regardless of whether I follow Alex's code oon the vid or the following, a parse error results.
$app = new \Slim\App([
'settings' => [
'displayErrorDetails' => true,
'db' => [
'driver' => 'mysql',
'host' => 'localhost',
'database' => 'opium3',
'username' => 'root',
'password' => 'root',
'charset' => 'utf8',
'collation' => 'utf8_unicode_ci',
]
],
]);
$container = $app->getContainer();
/*set up eloquent to use outside laravel*/
use \Illuminate\Database\Capsule\Manager as Capsule;
$capsule = new Capsule;
$capsule->addConnection($container['settings']['db']);
$capsule->setAsGlobal();
$capsule->bootEloquent();
Running the app produced this error:
Parse error: syntax error, unexpected '=' in /var/www/public/opium3/vendor/illuminate/database/DatabaseManager.php on line 65
I'm running this locally on a scotchbox vagrant set up, if that's relevant.
There's a similar question at
Parse error when run illuminate/database/capsule with bootEloquent() in PHP
but this answer doesn't resolve my issue, since the server is running php7.
I have also tried installing packages recommended by illuminate/database, installing php-mbstring, and editing the php.ini file, on the server, but the error persists.
Am I missing something obvious?
Make sure you're using at least PHP 7.1.
/illuminate/database/DatabaseManager.php is using a short hand version of the list()-construct which wasn't available until PHP 7.1.
The "old" way is to:
list($var1, $var2) = someFunction();
while you, since PHP 7.1, can also do:
[$var1, $var2] = someFunction();
The row the error is thrown in is this:
[$database, $type] = $this->parseConnectionName($name);
Note:
If you can't upgrade your PHP version from 7.0 to 7.1.3+, you need to use an older version of the Illuminate/Database-package. Use version 5.5 for PHP 7.0 and then 5.6+ on PHP 7.1.3+
I've got the following code which I want to run from CLI:
error_reporting(E_ALL);
ini_set('display_errors', '1');
require '/usr/share/nginx/www/aws-autoloader.php';
use Aws\Ec2\Ec2Client;
$ec2Client = Ec2Client::factory(array(
'key' => 'xxxxxxxxx',
'secret' => 'xxxxxxx',
'region' => 'us-east-1'
));
Am getting this error:
Parse error: syntax error, unexpected T_USE on line 5
The line that is causing the error is:
use Aws\Ec2\Ec2Client;
Is it not possible to import like this when using CLI?
Edit
PHP version:
PHP 5.3.6-13ubuntu3.9 with Suhosin-Patch (cli) (built: Sep 12 2012
19:00:27)
use statements should appear at the top of code - directly after the PHP tag open (or a namespace definition), or as the first lines in a class.
For an example of such a bug (solved) see https://github.com/browscap/browscap-php/issues/1#issuecomment-22737388
I want to deploy symfony2 application. On localhost works perfect, the only difference my web directory is in public_html, but when I installed on my prod server, after register some user, the exception has been thrown. Looks like unserializing can't decode, my entity "0:{}":
ContextErrorException: Warning: Erroneous data format for unserializing 'CodeCats\PanelBundle\Entity\User' in /home/progress/domains/progress-checker.pl/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 869
in /home/progress/domains/progress-checker.pl/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 869
at ErrorHandler->handle('2', 'Erroneous data format for unserializing 'CodeCats\PanelBundle\Entity\User'', '/home/progress/domains/progress-checker.pl/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php', '869', array())
at unserialize('O:32:"CodeCats\PanelBundle\Entity\User":0:{}') in /home/progress/domains/progress-checker.pl/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php line 869
at ClassMetadataInfo->newInstance() in /home/progress/domains/progress-checker.pl/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2444
at UnitOfWork->newInstance(object(ClassMetadata)) in /home/progress/domains/progress-checker.pl/vendor/doctrine/orm/lib/Doctrine/ORM/UnitOfWork.php line 2546
at UnitOfWork->createEntity('CodeCats\PanelBundle\Entity\User', array('id' => '1', 'username' => 'tomek11', 'email' => 'tomek11#gmail.com', 'password' => '2f5e325c351294588e238389d1cc86a39a0c58f2', 'grade' => 'USER', 'avatar_id' => null, 'companyEmail_id' => null), array()) in /home/progress/domains/progress-checker.pl/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php line 132
at SimpleObjectHydrator->hydrateRowData(array('id1' => '1', 'username2' => 'tomek11', 'email3' => 'tomek11#gmail.com', 'password4' => '2f5e325c351294588e238389d1cc86a39a0c58f2', 'grade5' => 'USER', 'avatar_id6' => null, 'companyEmail_id7' => null), array('id1' => array('name' => 'id', 'type' => 'integer'), 'username2' => array('name' => 'username', 'type' => 'string'), 'email3' => array('name' => 'email', 'type' => 'string'), 'password4' => array('name' => 'password', 'type' => 'string'), 'grade5' => array('name' => 'grade', 'type' => 'string'), 'avatar_id6' => array('name' => 'avatar_id', 'type' => 'integer'), 'companyEmail_id7' => array('name' => 'companyEmail_id', 'type' => 'integer')), array()) in /home/progress/domains/progress-checker.pl/vendor/doctrine/orm/lib/Doctrine/ORM/Internal/Hydration/SimpleObjectHydrator.php line 48
Additional info: The magic gpc in turned on.
Update
my check.php result:
** Mandatory requirements **
OK PHP version must be at least 5.3.3 (5.4.29 installed)
OK PHP version must not be 5.3.16 as Symfony won't work properly with it
OK Vendor libraries must be installed
OK app/cache/ directory must be writable
OK app/logs/ directory must be writable
OK date.timezone setting must be set
OK Configured default timezone "Europe/Warsaw" must be supported by your installation of PHP
OK json_encode() must be available
OK session_start() must be available
OK ctype_alpha() must be available
OK token_get_all() must be available
OK simplexml_import_dom() must be available
OK detect_unicode must be disabled in php.ini
OK PCRE extension must be available
** Optional recommendations **
OK Requirements file should be up-to-date
OK You should use at least PHP 5.3.4 due to PHP bug #52083 in earlier versions
OK When using annotations you should have at least PHP 5.3.8 due to PHP bug #55156
OK You should not use PHP 5.4.0 due to the PHP bug #61453
OK When using the logout handler from the Symfony Security Component, you should have at least PHP 5.4.11 due to PHP bug #63379 (as a workaround, you can also set invalidate_session to false in the security logout handler configuration)
OK You should use PHP 5.3.18+ or PHP 5.4.8+ to always get nice error messages for fatal errors in the development environment due to PHP bug #61767/#60909
OK PCRE extension should be at least version 8.0 (8.32 installed)
OK PHP-XML module should be installed
OK mb_strlen() should be available
OK iconv() should be available
OK utf8_decode() should be available
WARNING posix_isatty() should be available
Install and enable the php_posix extension (used to colorize the CLI output).
OK intl extension should be available
OK intl extension should be correctly configured
OK intl ICU version should be at least 4+
WARNING a PHP accelerator should be installed
Install and enable a PHP accelerator like APC (highly recommended).
WARNING short_open_tag should be disabled in php.ini
Set short_open_tag to off in php.ini*.
OK magic_quotes_gpc should be disabled in php.ini
OK register_globals should be disabled in php.ini
OK session.auto_start should be disabled in php.ini
OK PDO should be installed
OK PDO should have some drivers installed (currently available: mysql, pgsql, sqlite)
Ok it's the issue (and possible solutions):
http://www.doctrine-project.org/jira/browse/DDC-3120
https://github.com/symfony/symfony/issues/11056
For those still coming across this issue, updating the doctrine/orm dependency worked.
My new doctrine dependency line in composer.json:
"doctrine/orm": ">=2.2.3,<2.5",
Then I updated composer as per usual from the command line: php composer.phar update
Since it's the top Google result for this error I'll just paste the dirty quick fix here to get you going more easily.
Note: In nearly every case you shouldn't modify any vendor files like this. However, if you have some dependency problem which couldn't be solved for some reason here's the trick for you.
This is a Doctrine error, so you should modify the Doctrine ORM bundle a bit.
Add your PHP_VERSION_ID to the newInstance() function in
/vendor/doctrine/orm/lib/Doctrine/ORM/Mapping/ClassMetadataInfo.php
The final result looks like this for me:
public function newInstance()
{
// echo PHP_VERSION_ID; die(); // Uncomment this, in case you don't know your PHP_VERSION_ID
if ($this->_prototype === null) {
if (PHP_VERSION_ID === 50429 || PHP_VERSION_ID === 50513 || PHP_VERSION_ID === 50603 || PHP_VERSION_ID === 70009) { // This is the tricky line
$this->_prototype = $this->reflClass->newInstanceWithoutConstructor();
} else {
$this->_prototype = unserialize(sprintf('O:%d:"%s":0:{}', strlen($this->name), $this->name));
}
}
return clone $this->_prototype;
}
The original solution can be found here: https://github.com/symfony/symfony/issues/11056
I had the same issue. I solved it by updating "doctrine/orm" package in Composer.json to "~2.4" version and then running:
composer update doctrine/orm
from the command line. This should only update the concerned package. After this refreshing the webpage and/or logging in again and the error was gone.
Hope this helps.
I've been creating a php script for a project and have been running it on my development server which is running PHP 5.4.17
I need to move it over to my production server which is running PHP 5.4.19
When using the array_map function on my development server I got the results I needed with no problem.
On my production server I get the parse error:
Parse error: syntax error, unexpected '[' in /path/to/script/ on line 219
My code used was:
$arr = array_map(
function($results_titles, $results_image, $results_summary, $results_dates, $results_links) {
return ['title' => $results_titles, 'image' => $results_image, 'summary' => $results_summary, 'date' => $results_dates, 'link' => $results_links];
},
$results_titles, $results_image, $results_summary, $results_dates, $results_links
);
The new array syntax comes up with PHP 5.4.
So make sure your php version in your server is >= PHP 5.4
Note: the cli and the web server(eg: apache) could run different version of php.
I was trying to install Wordpress on our server to test, but in order to do that I had to upgrade our current PHP version to 5.3. I upgraded our PHP and I am now finding that our Purolator shipping module is no longer working. According to our host support the "purolator.php" file is missing data that the new version of PHP requires. Unfortunately, I can't revert our PHP version back and our programmer is away.
This is the error message I was able to get from our website host support team:
tail /var/www/vhosts/phantomcables.com/statistics/logs/error_log -f
[Thu Jul 19 08:34:28 2012] [error] [client 70.51.168.201] PHP Fatal
error: Class 'SoapClient' not found in
/var/www/vhosts/phantomcables.com/httpdocs/shippings/purolator.php on line
49, referer: https://phantomcables.com/index.php?dispatch=checkout.cart
These are lines 40 to 72:
function createPWSSOAPClient()
{
/** Purpose : Creates a SOAP Client in Non-WSDL mode with the appropriate authentication and
* header information
**/
//Set the parameters for the Non-WSDL mode SOAP communication with your Development/Production credentials
//echo DIR_SHIPPING_FILES."estimatingservice.wsdl";
$url = "https://webservices.purolator.com/PWS/V1/Estimating/EstimatingService.asmx";
$client = new SoapClient( DIR_SHIPPING_FILES."estimatingservice.wsdl",
array (
'trace' => true,
'location' => $url,
'uri' => "http://purolator.com/pws/datatypes/v1",
'login' => PRODUCTION_KEY,
'password' => PRODUCTION_PASS
)
);
//Define the SOAP Envelope Headers
$headers[] = new SoapHeader ( 'http://purolator.com/pws/datatypes/v1', 'RequestContext',
array (
'Version' => '1.0',
'Language' => 'en',
'GroupID' => 'xxx',
'RequestReference' => 'Rating Example'
)
);
//Apply the SOAP Header to your client
$client->__setSoapHeaders($headers);
return $client;
}
Any help would be greatly appreciated.
It seems like you did not have installed the php-soap package on your server.
Type
phpinfo();
in your code and check if 'Soap Client' is 'enabled'.
If not, I don't know your distribution and package manager, but here is the code for Fedora I use:
$ yum install php-soap
I suggest to do it with your programmer back or a sys admin by your sides, you never know what could happen. A backup is also useful before any installation!
You will need to add (or remove any comment characters before)
extension=soap.so
to your php.ini file, and then restart the web server.
If you are having trouble finding your php.ini file, create a page with the following:
<?php phpinfo();
and load that file in your browser.
On some systems, this setting may not actually live in php.ini. For example, if you are using Zend Server, the setting would live in /usr/local/zend/etc/conf.d/soap.ini.
So we reverted back to an older version of PHP, and re-enabled SOAP. apparently that was the issue, not sure why that didn't work with the newer version of PHP.
Again thank you for all of your help. This is a great community.
It is already posted here
Do the following:
Locate php.ini in your apache bin folder, I.e Apache/bin/php.ini
Remove the ; from the beginning of extension=php_soap.dll
Restart your Apache server
Look up your phpinfo(); again and check if you see a similar picture to the one above
If you do, problem solved!
Enable the SOAP extension, require it in your composer.json like so:
{
"require": {
"ext-soap": "*"
}
}