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.
Related
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!
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.
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 think it's a server configuration error and not a php syntax error.
running Apache/2.2.20 (Ubuntu) and PHP Version 5.3.10-1ubuntu3.7
Error :
PHP Parse error: syntax error, unexpected '[' in /home/thomas/Documents/myimouto/config/application.php on line 30
here is the code
$config->load_files = [
'app_functions.php',
'Moebooru/Resizer.php',
'dtext.php'
];
$config->safe_ips = [
'127.0.0.1',
'192.168.1.###'
];
Check your PHP version first. The short hand form for the array declaration [] was only introduced in PHP's version of 5.4 (if am not mistaken). The previous versions only supported the () delimiters.
So, I suggest you try changing that line to:
$config->safe_ips = array(
'127.0.0.1',
'192.168.1.###'
);
or better yet, update to PHP > 5.4Yeah..
I'm trying to build php_perl.dll and am getting errors, but my understanding of building these extensions is limited (obviously). So i need to get this compiled, or, alternatively, point me to a pre-built php_perl.dll that will work with PHP 5.2.17. The http://pecl4win.php.net site is dead, and what little i can find at http://pecl.php.net/package/perl isn't much help either.
I've installed Perl (tried 64bit then x86), PHP (installed with XAMPP), and Visual Studio 6. Windows 7 64bit. PERL_HOME set to c:\perl.
This command
msdev perl.dsp /MAKE "perl - Win32 Release_TS"
Results in 102 errors, like this:
--------------------Configuration: perl - Win32 Release_TS--------------------
Compiling...
php_perl.c
C:\Perl\lib\CORE\sys/socket.h(72) : error C2061: syntax error : identifier 'win32_accept'
C:\Perl\lib\CORE\sys/socket.h(72) : error C2059: syntax error : ';'
C:\Perl\lib\CORE\sys/socket.h(72) : error C2146: syntax error : missing ')' before identifier 's'
C:\Perl\lib\CORE\sys/socket.h(72) : error C2061: syntax error : identifier 's'
C:\Perl\lib\CORE\sys/socket.h(72) : error C2059: syntax error : ','
C:\Perl\lib\CORE\sys/socket.h(72) : error C2059: syntax error : ')'
...
C:\Perl\lib\CORE\sys/socket.h(98) : error C2059: syntax error : ')'
C:\Perl\lib\CORE\win32.h(420) : error C2079: 'Wservent' uses undefined struct 'servent'
C:\Perl\lib\CORE\iperlsys.h(1143) : error C2143: syntax error : missing ')' before '*'
C:\Perl\lib\CORE\iperlsys.h(1143) : fatal error C1003: error count exceeds 100; stopping compilation
Error executing cl.exe.
php_perl.dll - 102 error(s), 0 warning(s)
Any ideas on what i'm doing wrong?
No answer for this question?
I just resolved compilation errors for php 5.3.13 on Windows by slightly modifying the new 1.0.1 php_perl.c source code (line 31):
old:
# define _WINSOCK2API_ /* using winsock.h instead of winsock2.h */
new:
# ifndef _WINSOCK2API_
# include <winsock2.h>
# endif
For the compilation follow the tutorial from this page (http:/ /www.crazyws.fr/tutos/compiler-php-et-ses-extensions-sur-windows-SJ5GT.html), sorry for the french.
Basically install Visual Studio 2008 Express WITH SP1 (otherwise a build error occurs), then uninstall any 2008 Runtime, then install the Windows SDK 6.1 (2008 Server) to compile VC9 builds. I also used a Perl installation from ActiveState (version 5.8.0, ActivePerl-5.8.0.805-MSWin32-x86.msi, not tested with further versions).
Then download the php sdk and deps from http:/ /windows.php.net/downloads/php-sdk/, php sources, sources of extension from http:/ /pecl.php.net/package/perl, unzip directories as described in the tutorial, modify php_perl.c as above.
Then open the CMD shell of the Windows SDK and type:
setenv /xp /x86 /release
cd <root_directory>
bin\phpsdk_setvars.bat
cd <php_src>
buildconf --force
configure --help
configure --with-perl=shared --with-extra-includes="<perl_lib_CORE_directory>" --with-extra-libs="<perl_lib_CORE_directory>"
nmake php_perl.dll
I compiled my dll on windows 7 Pro 64-bit and tested it on my WampServer installation. The .phpt files in the sources of the extension are pretty self-explanatory on how to use it.
For info another version of the file is also available for php 5.4 on this github repo (https:/ /github.com/do-aki/php-ext-perl).
Sorry for the long answer, but the README file of the extension regarding installation on Windows is obsolete and there is no support which I found pretty lame.
Regards