DeveloperJoy Logo DeveloperJoy

How to deprecate methods correctly in PhpStorm?

April 13, 2024
How to deprecate methods correctly in PhpStorm?

Did you know that PhpStorm can help you a lot deprecating and updating old methods. You can use the power of the IDE to make the changes for you and avoid errors.

TL;DR

How to deprecated methods

PhpStorm comes with a #[Deprecated] PHP tag that you can use to deprecate methods, but adding a reason and a replacement so you IDE will be smart enough to make the changes just for you.

#[Deprecated(
	reason: 'Use user_parameter_is instead.', 
	replacement: 'user_parameter_is(false, %parameter0%)')
]

Then, while using a deprecated method or function you will see the name crossed out, and by pressing alt + enter, you can automatically replace it with the new alternative.

As you can see, in the replacement string, I'm using %parameter0% to pick the first parameter of the deprecated function call, but there are other attributes that you can use to customize the replecement.

Here is the full list of attributes availables:

  • %parametersList%: parameters of the function call. For example, for the f(1,2) call, %parametersList% will be 1,2.
  • %parameter0%,%parameter1%,%parameter2%,...: parameters of the function call. For example, for the f(1,2) call, %parameter1% will be 2.
  • %name%: For \\x\\f(1,2), %name% will be \\x\\f, for $this->ff(), %name% will be ff.
  • %class%: If the attribute is provided for method m, then for $this->f()->m(), %class% will be $this->f().

Now you can intelligently replace the old code without hassle.

← Go back to the blog

Work with me

Do you own a company or need help with your Laravel project? I can help you with that. Check the plans and let me know if you have any questions.

Get 1 month free with yearly plan during checkout.

Technical Advisor

$ 3 ,995

/m

What's included:

  • Lead your team to a better code architecture, testing mentality, clean code, and more.
  • Lead knowledge-sharing sessions depending on current company status and requirements.
  • Help with product and technical decisions.
  • Pause or cancel anytime.

Integrated Senior Developer

$ 5 ,995

/m

Not available

What's included:

  • Includes all Technical Advisor services.
  • Engages as a team member in daily tasks.
  • Participates actively in day-to-day development.
  • Direct communication:
    Slack, and meetings included.
  • Pause or cancel anytime.

Want to talk first?

Ok, just book a call now.

FAQ