Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save application2000/7c2032f7c9faecb3e9c9e8ad0c5bfbd7 to your computer and use it in GitHub Desktop.
Save application2000/7c2032f7c9faecb3e9c9e8ad0c5bfbd7 to your computer and use it in GitHub Desktop.
PhpStorm regex to replace PHP object-like accessing to PHP array-like accessing
Do you keep modifiying $my_variable->foo to $my_variable['foo'] over and over everyday? This regex is for you.
text to replace : (\$some_variable)(\->)([\w]+)
replacement : $1\[\'$3\'\]
Backup your files to prevent any problems. Use this with caution. At your own risk.
Usage:
1. Keyboard shortcut Cmd + R or equivalent to trigger a text replace
2. Click on the regex checkbox
3. Make sure case-sensitive is on (Match Case checkbox)
4. Change some_variable with your own
5. Click on Replace or Replace all
6. Enjoy the beauty of regular expressions!
Tested in PhpStorm 2016.3.2 on macOS Sierra 10.12.3
PS: If there is some problem do Cmd + Z to undo changes.
Have a nice day.
@application2000
Copy link
Author

application2000 commented Dec 16, 2019 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment