Detect deprecated required parameters after optional parameters

In php 7 or older(I guess) this is ok to use a nullable parameter before a required parameter. But in php 8 it's not ok:

function foo($var1=null, $var2){ 
...
}
Deprecated: Required parameter $var2 follows optional parameter $var1 in ... on line ... 

Is there any way to detect optional parameters before required ones?

1 comment
Comment actions Permalink

Hi there,

Sure. The inspection that detects this called "Optional before required parameter". You can find out the inspection name from the Alt+Enter (light bulb) menu (screenshot below) or maybe even right from the Problems toolwindow:

We now know the inspection name ... so we can run just that specific inspection using "Code | Analyze Code | Run Inspection by Name": https://www.jetbrains.com/help/phpstorm/running-inspections.html#run-inspections-manually

Just type some relevant text to locate that inspection:

Once you have it -- select the scope: current file/folder, certain scope or a whole project .. and after IDE analyses your code you will get a new tab in the Problems tool window with all the results: https://www.jetbrains.com/help/phpstorm/inspection-results-tool-window.html

0

Please sign in to leave a comment.