Docker PHP 5.2.17 lint doesn't detect anonymous function - php

So, I am trying to set up several kinds of tests for several kinds of projects.
One project is still running on PHP 5.2.17 (yeah I know :( ).
So I have been searching the Docker Hub for PHP 5.2.17 images, which is de PHP version running on the production machine.
On the production machine we recently encountered a fatal error on a PHP file in which we used an anonymous function - a feature that has been added to PHP as of version 5.3.
A simple lint on that machine detects that:
php -l corrupt_file.php
The above will show an error like "unable to parse PHP file".
However, I have tried out several PHP 5.2.17 docker images, and executing the same lint in them results in "No errors detected".
I am completely lost. Are those PHP 5.2.17's another more recent version of PHP instead??

I just found out what the problem is:
All the docker images have SHORT_OPEN_TAGS set to "off" in the php.ini.
In that case the PHP linter simply "doesn't see any parse errors" because it doesn't see any PHP.

Related

VS Code shows me errors due to local PHP version

I am currently working on a PHP Laravel project. For this project I need at least PHP 8.1, so I have a PHP Docker instance. On my Mac I have php 7.3.24. The project runs as expected. But my IDE (VS Code) gives me an error message in many places due to the local PHP version. For example, the typehint of class variables.
In addition, included libraries are not recognised when I want to initiate them (undefined type).
My question: Do I have to upgrade the local PHP version or is there a setting in the IDE?

PHP version supposedly wrong, but seems to be correct

I am trying to make a bash script on my server to clear the Grav cache. When I run it from the server, it works fine. But when I run it from my local machine, over SSH, I get an error: You are running PHP 5.6.36, but Grav needs at least PHP 7.1.3 to run. However, php -v on my server returns PHP 7.2.11 (cli) and on my local machine returns PHP 7.1.23 (cli). I do not begin to understand what the problem might be.
In the end, I could not resolve the issue of the different PHP versions, but solved the problem by including the path to the correct PHP version in the server script. So, locally I have ssh jeremygrav#ps589716.dreamhostps.com "bash ./clear.sh" and on the server, the script contains /usr/local/php73/bin/php bin/grav cache --all.
That works fine, although I realise it avoids the problem rather than solving it.

XHP with PHP 5.4 not affecting the parser when script is called via Apache

I recently built XHP 1.5 from source, and installed it on an existing web server. The web server is running PHP 5.4.32, Apache 2.2.15 calling PHP using mod_php (not fastcgi), CentOS 6.5. All our existing PHP code (that doesn't rely on the new XHP syntax) still works great, including other extensions like Imagick, curl, and JSON.
Using a test file based on the XHP installation test:
<?php
echo "XHP!\n";
exit;
echo <a/>;
?>
This works as expected when run from the command line. (It prints XHP! then exits. The doesn't cause the parser to fail, but doesn't display either, since we're not loading in the dependencies.)
When I fetch this script through Apache, I get the error
Parse error: syntax error, unexpected '<' in /var/www/html/bloom/play.php on line 4
Getting phpinfo() via Apache shows that XHP is loaded, extension_loaded("xhp") through Apache returns true.
What could be causing XHP to work from the command line, but to not work (not even parse) when run via Apache?
One possible reason is a difference in versions of PHP, especially since you're building XHP from source. I've encountered similar odd behavior on a shared host that had multiple versions of PHP installed. Compare the PHP version reported by Apache (look at the phpinfo() output) against the version you're using at the command line php -v. If there's a difference, that could be one explanation for the problem you're having.
After looking into more detail for how my production server (not working) differed from my test servers (working) I discovered that all servers had APC 3.1.15 installed, but in production, APC's opcode cache was disabled in /etc/php.d/apc.ini:
# BAD NEWS
apc.enable_opcode_cache=0
As it happens, this is not what we wanted for unrelated performance reasons.
Turning on APC's opcode cache, by changing this line in /etc/php.d/apc.ini and restarting Apache caused XHP to immediately begin working:
# WORKING
apc.enable_opcode_cache=1
I've also been able to resolve the problem by uninstalling APC altogether (although that's not practical in my app).
That would also explain why it worked from the CLI and not from the web--all my servers have apc.enable_cli=0, so APC wouldn't interfere with XHP from the CLI.

Eclipse Juno PHP Tools (PTI) Error

I just found out about PTI (see http://www.phpsrc.org/) but I can't seem to get it to work in Eclipse Juno.
I also have PDT installed, with my PHP Executables, PHP Interpreter, and Execution Environments all set up under my workspace preferences. Each PHP Tools feature I want to use is configured to use the PHP Executable and PEAR library I have set up.
When I try to run any of the tools (PHP CodeSniffer, PHP Copy/Paste Detector, PHP Depend, PHPUnit, or PHPMD), I get an alert that say the following:
'PHP Depend' has encountered a problem.
An internal error occurred during: "PHP Depend".
Details >>
An internal error occurred during: "PHP Depend".
org.eclipse.php.internal.debug.core.launching.PHPLaunchUtilities.getCommandLine(
Lorg/eclipse/debug/core/ILaunchConfiguration;
Ljava/lang/String;
Ljava/lang/String;
Ljava/lang/String;
[Ljava/lang/String;
)[Ljava/lang/String;
Has anyone been able to get this awesome tool to work on Juno? If so, how?
I had the same problem.
Downgrading PDT from version 3.2.1 to 3.0.0 (installed from General Tools of 'Indigo') sorted out the problem for me. It works now fine.
I checked many possible workarounds (begin of path here: internal error occurred during: "PHP CodeSniffer". in zend studio 10.0 ) but just above solution gave results.

MAMP PHP vs Apple's installed version

I would like to use MAMP's version of PHP for my local PHP testing and development. I understand that Macs come with a version of PHP installed. I have installed MAMP and everything seems to be going smoothly except error reporting.
In Terminal I have checke which version of PHP my machine is using and it is not the one from MAMP. I have changed MAMP's php.ini files to report all errors. I am not getting any errors in my testing. I am inserting obvious errors to test for.
My questions are:
How can I disable or remove the preinstalled version of PHP?
How can I set my machine to use only MAMP's version of PHP?
Can I test multiple versions of PHP at once? Is it recommended?
How can I stay up to date with the latest version of PHP? Is it like normal Software Updates?
-Josh
Add/change following line in ~/.profile or ~/.bashrc (for bash):
export
PATH=/Applications/MAMP/Library/bin:/Applications/MAMP/bin/php/php5.2.17/bin:/usr/local/bin:$PATH:/opt/local/bin
and after that please re-login (or just execute e.g. /bin/bash).
From http://drupal.org/node/1464236
You can change the version # to the version you want.

Categories