Is this PHP function definition wrong? - php

I've a moodle 3.4 installed on a server and cron fails.
There is a function definition that causes the error (PHP version is 7.0.x):
public static function create($time, int $courseid, int $categoryid = null) : calendar_information {// code here}
Is this a right syntax or maybe is this a bug? I have no good knowledge on PHP.
This is the error I am getting:
PHP Parse error: syntax error, unexpected ':', expecting ';' or '{' in /usr/home/xxx/www/calendar/lib.php on line 1047

Solved:
The crontab was pointing to the 5.6 version. So when I executed php -v from command line, the outpot was php 7.0.26. But cron process crashed because php was 5.6 version... Now it runs perfectly.
Thanks for your hints, all have been very useful.
Have a nice day!

Related

Error 500 on /projects when doing first time install of directus

I've installed the current version of directus on my VPS (Debian 10, PHP 7.3, Apache 2.4.38).
When running the browser-based install, an error appears in the /logs saying:
[2020-02-27 20:31:59] api[].ERROR: ParseError: syntax error, unexpected '?', expecting variable (T_VARIABLE) in /var/www/clients/client0/web16/web/vendor/symfony/translation-contracts/TranslatorTrait.php:44
For me, it sounds like if it was a wrong PHP version, but PHP 7.3 is running.
I don't know whether this is important, but after ignoring this, on the page where you enter the database connection parameter, the POST to /server/projects returns with Error 500 "Internal Server Error".
I cannot find any log entry.
How can I find the reason for the 500?
Is it possible to configure the application without the browser-based installation?
Edit
Switched back from master to v8.5.5 and in this source code, there is a trans function:
/**
* {#inheritdoc}
*/
public function trans(?string $id, array $parameters = [], string $domain = null, string $locale = null): string
{
if (null === $id || '' === $id) {
return '';
}
if (!isset($parameters['%count%']) || !is_numeric($parameters['%count%'])) {
return strtr($id, $parameters);
}
So there is indeed a type ?string.
My PHP version should be able to handle this, IMO. But before, I had Debian 9 with PHP 7.0 where I had the same problem and which was the reason to upgrade Debian from 9 to 10.
Is it possible that a compile-cache from Debian 9 is still present?
But I suppose this is not the main problem. My problem is that I receive an error 500 and besides the 500-log-entry in apache error.log, there is nothing I can see to diagnose this issue.
A handy way to find syntax errors when error reporting and logs don't yield anything is to try and run the script through command line using the lint flag, e.g.
php -l path/to/file.php
TranslatorTrait.php seems to be corrupted, because line #44 actually should be:
public function trans($id, array $parameters = [], $domain = null, $locale = null)
So obviously, there should be no unexpected ?. Try to refresh composer dependencies with:
rm -rf vendor/*
And then:
composer clearcache && composer install

Error 500 on a working docker container

I'm using a slimframwork 3 app on laradock (nginx, mariadb, phpfpm, php 5.6) so I made a stupid syntax error:
$view->addExtension(new \Slim\Views\TwigExtension(
$container->router,
$container->request->getUri(),
));
the comma after the getUri() was giving me error 500 on chrome and that was frustration so I tried my app on wamp on windows and I get:
Parse error: syntax error, unexpected ')' in C:\wamp64\www\app\bootstrap\app.php on line 21
why was I having a 500 error with no clue of what was wrong.
P.S. I've set displayErrorDetails to true
Shoutout to Phil who solved this issue.
So when you use laradock and you come to a situation like this and you want more specific details about the error, you can either check your php-fpm container logs with:
docker logs -f <your container>
or set the "display_errors=On" on laradock/php-fpm/laravel.ini
and you'll see your error message on your browser instead of error 500.

Yii2 init error on PHP7

I've a problem when i try to switch my project from dev enviroment to prod, the project is a git repository I push to my server, now I need to switch to production and I try to runphp init on server but all time I receive the same error:
Parse error: syntax error, unexpected T_FUNCTION in /my/root/path/init on line 70
where /my/root/path/ is the base path where I push code.
Someone have any idea about this error?
Based on my previous answer and the comment:
Try
array_walk($skipFiles, function(&$value, $key, $data) {
$value = $data[1] . '/' . $value;
}, [$env, $root]);
#Marber: Return the same error, a similar solution is function resolveBug($value) { $value = "$root/$value"; } array_walk($skipFiles, resolveBug($value)); and this resolve the bug but the procedure generate anothe error on line 81: Parse error: syntax error, unexpected '['... and the code is $callbacks = ['setCookieValidationKey', 'setWritable', 'setExecutable', 'createSymlink'];
I'm guessing there is PHP 7 on the CGI side and CLI is PHP < 5.3 and that is why console commands don't work.
Check your console PHP version by running
php -v
in console.

php 5.3.24 - cli differs from http while using function()[i]

Why array indexing [i] won't work on functions while invoking the script from command line? (PHP version is on question in order to filter views.)
Test case:
<?php
echo explode( ' ', php_uname() )[0];
?>
Command line output:
> php -n -f borrar.php
Parse error: syntax error, unexpected '[', expecting ',' or ';' in borrar.php on line 3
Browser output:
Windows
EDIT
XAMPP php version was different from another PHP version that was previously installed in the system. That explains why I got different behaviours.

PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR in C:\Domains\xyz.com\wwwroot\123\index.php on line 26

I'm new to PHP and MySQL.
When I run my files on the localhost, everything runs just perfect! But when I upload all files to live real domain I get this:
PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR in C:\Domains\xyz.com\wwwroot\123\index.php on line 26
This is line 26 in index.php:
GetApplication()->GetUserAuthorizationStrategy()->ApplyIdentityToConnectionOptions($result);
My web hosting provider has PHP and MySQL.
Any help is highly appreciated.
This is it:
function GetConnectionOptions()
{
$result = GetGlobalConnectionOptions();
$result['client_encoding'] = 'utf8';
GetApplication()->GetUserAuthorizationStrategy()->ApplyIdentityToConnectionOptions($result);
return $result;
}
This was introduced in PHP 5. Where ever you are deploying to really needs an update because it is running PHP 4.
Test case:
<?php
class TestingClass
{
function test()
{
return $this;
}
}
function test()
{
return new TestingClass();
}
test()->test();
PHP Lint v5.0.0:
C:\PHP500>php -l E:\testcase.php
No syntax errors detected in E:\testcase.php
C:\PHP500>php -v
PHP 5.0.0 (cgi-fcgi) (built: Jul 13 2004 21:39:41)
PHP Lint v4.4.9:
C:\PHP449>php -l E:\testcase.php
<br />
<b>Parse error</b>: syntax error, unexpected T_OBJECT_OPERATOR in <b>E:\testcase.php</b> on line <b>16</b><br />
Errors parsing E:\testcase.php
C:\PHP449>php -v
PHP 4.4.9 (cgi-fcgi) (built: Aug 7 2008 15:04:24)
There is a space between - and >
GetApplication()->GetUserAuthorizationStrategy()- >ApplyIdentityToConnectionOptions($result);
This means "minus greater than". Remove the space.
2nd try: Is GetApplication really a function?

Categories