Not seeing how to add PHP 5.2 to PHP language level

Our project is in PHP 5.2 (we have no choice over that) but PHPStorm's language level only goes down 5.3. How do I add 5.2?

10 comments
Comment actions Permalink

>so I'm confused on whether these are accurate or who's setting those version numbers.

In theory -- JB stuff .. or if somebody will submit PR to the official repo at https://github.com/JetBrains/phpstorm-stubs

 

>then I'm confused on why Ctrl+clicking one of the functions brings me to that document (date_c.php). Do the stub files have nothing to do with Language Level?

As I have stated all this time -- No. Should be in the future (as per ticket mentioned in my previous comment) but not till now.

There is only one stub and Ctrl+Click takes you to the definition -- be it your code, 3rd party library or bundled stub.

 

>So if we upgrade to the latest version of PHPStorm and clone a stub, can I make that only be for up to version 5.2? 

I guess yes -- but it only shows what's in there .. so you will have to make those stubs 5.2-only first.

 

I guess you may ask about progress in that ticket .. or wait until somebody from JB devs/officials will answer here.

1
Comment actions Permalink

Hi there,

There is no way to add 5.2 as language level. Since very beginning PhpStorm supports PHP 5.3 and newer only.

The decision was made to not add separate support for unsupported-now-for-a-long-time 5.2 -- https://youtrack.jetbrains.com/issue/WI-16119

-----

What is language level in PhpStorm? It checks that language constructs (keywords/syntax/etc) are valid for that language.

Since IDE does not support 5.2 .. I may only suggest to use 5.3 as language level. If you know what constructs need to be used there (or better say -- 5.3 features that should not be used here) then you should not have any issues writing your code -- based on the comments in aforementioned ticket (and related/duplicate tickets) it all works OK.

0
Comment actions Permalink

PHP 5.2 was unsupported for a long time when PHPStorm version 1 came out?

0
Comment actions Permalink

From https://en.wikipedia.org/wiki/PHP#PHP_5

PHP 5.2 -- Released 2 November 2006

PHP 5.3 -- Released 30 June 2009

 

Based on https://confluence.jetbrains.com/display/PhpStorm/Previous+PhpStorm+Releases

Version 1.0.2 (build 95.503) -- 8 Aug 2010

 

0
Comment actions Permalink

PHP 5.2 went unsupported 6 Jan 2011

0
Comment actions Permalink

I've run into another problem where PHPStorm is telling me a function exists which doesn't in PHP 5.2, yet I've got the PHP language level set to the lowest on the list, 5.3. Since PHPStorm came out when PHP 5.2 was still supported by Zend (for about a year and a half), it should also include the language level.

If there's any way for me to be able to install or configure PHPStorm to use PHP 5.2 language level, please let me know.

0
Comment actions Permalink

Specifically I'm editing code using the PHP built-in DateTime class, but am unable to see which exact functions are available only to 5.2 as php.net's documentation says date_diff is available but it's actually not in 5.2... I'm not seeing any resource that tells which functions and behaviors are ONLY in 5.2.

I did find C:\Program Files (x86)\JetBrains\PhpStorm 10.0.3\plugins\php\lib\php.jar which contains (in the editor) com > jetbrains > php > lang > psi > stubs > data> date_c.php but (I'm guessing) only the PHP 5.3 version which is what's selected in my Settings > Languages & Frameworks > PHP > Development Environment > PHP Language level.

It looks like I can retro-fit PHP code into this .jar file, so how would I do that?

If I can't do that, where do I find  the exact PHP 5.2-only documentation for the DateTime object? I'm having to guess trial and error on how to use the functions.

0
Comment actions Permalink

As far as I'm aware PhpStorm does not yet has the (fully working) version-dependant stub.

I mean -- there is a ticket ( https://youtrack.jetbrains.com/issue/WI-16509 ) which meant to have some work to be done on that .. but so far (based on 2016.3 EAP version) I do not see much progress here. I do see that relevant @since tags were added to most classes/functions/constants/etc .. but do not see how IDE uses them. Plus, such tags are done for actual classes/functions/etc but do describe/affect actual parameters or their values.

I can set PHP Language Level to be 5.3 (the lowest possible) and use 5.4-only constant (e.g. ENT_SUBSTITUTE from htmlentities() .. or use Error class (PHP 7.0) in catch section) with no warnings from IDE side .. as Language Level still reflects only language constructs/keywords and not constants/function availability or parameters (which is what you need here). IDE will not warn me if I will use some parameter that exist in latest PHP only ("latest" is based on what stub files are made from/referring to).

Since 2016.2 (or maybe since 2016.3, not sure) -- you would be able to clone stubs repository and edit them as you wish (look at yellow message bar on top + actual current stubs on the right side):

-----

As for your "5.2-only documentation" moment. The best I can suggest is to use php.net website -- you can use "View | External Documentation" on the function/class you are interested (same way as you use built-in documentation; BTW -- you can open it from Quick Documentation popup as well) and it will take you to the official doc site where you can check all relevant info. E.g. for your DateTime::diff it will take you to http://php.net/manual/en/datetime.diff.php where you can see that this method is "PHP >= 5.3; PHP 7" only.

0
Comment actions Permalink

Thanks for the info Andriy.

When I Ctrl+click one of the implemented DateTime functions (like $dateTimeObject->modify('+6 months')) it brings me to that date_c.php file but the DateTime class comments there don't show which version of PHP they're for, only in the above comments in interface DateTimeInterface and class DateTimeImmutable does it state a PHP version, but only 5.5 and 5.6, so I'm confused on whether these are accurate or who's setting those version numbers.

If the Language Level is only for keywords/constructs but not constants/function availability then I'm confused on why Ctrl+clicking one of the functions brings me to that document (date_c.php). Do the stub files have nothing to do with Language Level?

So if we upgrade to the latest version of PHPStorm and clone a stub, can I make that only be for up to version 5.2? I'm not sure that would be effective anyways if function/class availability has nothing to do with selected Language Level.

0
Comment actions Permalink

Thanks for the clarification, but it was not stated the whole time that stubs and Ctrl+clicking have nothing to do with Language Level, it was initially stated "It checks that language constructs (keywords/syntax/etc) are valid for that language." (etc can be interpreted very subjectively) then later stated functions/classes are not checked for availability, and also based on the rest of the reply was why I was confused, but there were multiple things addressed here, such as validation and error messages, which apparently also have nothing to do with the stub, so I'm not sure the advice of creating a stub specifically for 5.2 would address any of the questions I had other than Ctrl+clicking to get the correct function commentary in the particular stub I need to use (which I guess I'd have to write myself for every PHP function and again as you clarified has nothing to do with selected Language Level anyways).

Why validation, error messages, Ctrl+clicking, language constructs/keywords and constants/function availability or parameters are not all tied together with the Language Level and stub is beyond me; PHPStorm has been out for 6 years and this seems like the most basic thing an IDE should tie together for validation and suggestions and lookups like other editors do like Eclipse and NetBeans. I can't tell if the team is unable to figure out how to tie these things together properly or is just unwilling or not given enough time or resources.

0

Please sign in to leave a comment.