Automatically convert short array syntax to long (traditional) in PhpStorm? - php

How to automatically convert short array syntax to long(traditional) in PhpStorm?
I used the feature "Code -> Inspect Code" in PhpStorm and then one by one click convert short syntax to long.
Inspect code
Manually convert
There has to be a way to automate this job? Are there macros in PHPStorm?

go to Settings(Ctrl + Alt + S)-> Editor -> Code Style -> PHP -> Code Conversion -> Array Declaration Style -> tick Force short declaration style Checkbox.
press OK -> press Ctrl + Alt + L -> voila

Bartosz is right. To avoid manual work you can use Short Array Syntax Converter tool with revert (short into long array syntax) option. But be aware, that
Reverting has not yet been thoroughly tested, so use with extreme
percaution!

I'm afraid it's not possible. If it was a failing inspection, there would be a "Fix all problems in file" option in the submenu. Intentions don't have this functionality.

Have You tried setting PHP version to 5.3 and then only search for this via Inspect code? Don't have PhpStorm installed anymore.

Related

PhpStorm how to detect/highlight closing "tag" in PHP's alternate syntax of contol structures

Pretty much what the title says. Is there a way to make PhpStorm highlight the closing "tag" when using PHP's alternate syntax for control structures?
Take a look at this sample code for example:
<?
if($x==5) {
echo "x is equal to 5";
}
?>
If i put the cursor next to or before the opening/closing brace, PhpStorm will automatically highlight the matching opening/closing brace.
Now, if we write the same code but this time using PHP's alternate syntax for control structures, we end up with something like this:
<? if ($x==5): ?>
x is equal to 5
<? endif; ?>
In this case, PhpStorm will not highlight either the opening "if" or the closing "endif;". Is there a way to make it highlight it?
Unfortunately current versions of PhpStorm cannot do that.
https://youtrack.jetbrains.com/issue/WI-14517 -- watch this ticket (star/vote/comment) to be notified on any progress. So far it has not been associated with any specific future version (not currently planned for implementation).
Related: https://youtrack.jetbrains.com/issue/WI-566
The 2017 version of PHPStorm now supports it. But apparently they are having issues with it that they turned off this feature, they did not mention what the issue is though. But you can still enable it by going to: Find Action->Registry->php.brace.alt.syntax
See response here Alternate PHP syntax

Sublime Text 3 - PHP - object operator and double arrow operator

Recently I've begin moving to sublime text 3 from Netbeans.
I've discovered almost all needed features but still can't find one.
There is a cool feature in Netbeans:
It does the following. If I have such code:
$product = new Product;
$product->someMethod();
I don't need actually to type - and then shift + > to get -> . It's enough just to presss - sign and Netbeans figures out on his own that it should be -> .
The same is applied to array.
I understand that Sublime doesn't do as deep code analysis as Netbeans does.
Of course it would perfect solution if it could figure out like Netbeans does.
But I would happy to replace - sign on numpad keyboard to -> always.
I've tried snippets. It looks like this:
It works ok. But only if it goes as the first symbol in the word.
But then I need to reference an object referencing never goes first.
I can't believe that all people type manually every time - and shift+> to get referencing the object. There must be better way.
Any ideas? How did you tackle this problem?
Looks like there is no silver bullet which would kill any beast.
Though ST is a cool editor it's just editor, it's good for js, scss,css, python where Netbeans sucks but too bad for php.
Probably I would be happy with ST for PHP if I didn't know that you can get more boosting using full-blown IDE.
So frontend development will be carried on ST and backend on Netbeans.
Edit
Of course I tried the whole bunch of available plugins. This is the list of tried:
To replace the - key with -> in all situations in Sublime Text (meaning if you want to write, for example 1 - 2, you would have to type 1 -backspace 2, you can do the following:
From the Preferences menu in Sublime Text
Click Keybindings - User
Write [{ "keys": ["-"], "command": "insert", "args": { "characters": "->" } }] (note that this assumes that you don't already have anything in the user keybinding file. If you do, before the ] at the end of the file, type , and the above without the enclosing [ and ] characters. The file needs to be a valid JSON array of keybindings.)
Save it
Try typing - and see the magic
You may be able to do some magic with contexts to get this keybinding only for PHP syntax files, or you could just write a simple Python plugin that your keybinding would execute, which would enter - in the document if it is not a PHP file and -> if it is.

Netbeans code format braces in PHP single line statements

Intro
Im developing PHP in NetBeans IDE 7.2 (Build 201207171143) and I love the formatting to clean up my code in my custom format.
At the moment I work in a group with colleagues. Some of my colleagues are used to write single line statement without braces (I think this is bad practice).
Examples
What my colleagues do:
<?php
if($stackoverflow == 'Cool')
echo 'Stack Overflow is Cool!';
?>
What I want when I format the code.
<?php
if($stackoverflow == 'Cool') {
echo 'Stack Overflow is Cool!';
}
?>
Question
So what I am looking for is the setting to achieve this. I can find every other setting to have nice braces.
Tools -> Options -> Editor -> Formatting -> PHP
WhatHaveITried
I have found this but I think this isn't the way for what I want to achieve since he talks about macros.
Could someone help me with this?
I am not sure if u have find the solution or not
Tools -> Options -> Editor -> Formatting
Language: PHP
Category: Braces
Select "same line" for all
Agree on a shared coding style! Don't rely on your editor to format and unformat code for you.
As for this example, I would argue that using brackets is better since it's less error prone - but this is something you have to agree upon with your collegues!
Ok so it isn't possible I guess.
It is possible to format braces in PHP.
This is an example:
I finally found the answer to this. It is found under Options -> Editor -> Formatting -> select PHP under the language drop down -> select "Wrapping" category -> scroll down to see "If Statement" and select "Never".

autocomplete in eclipse

I have been using gvim for a while and now im trying eclipse and a feature that I really miss is the auto complete. Not just typing pre and getting preg_replace as a suggestion, but if I have a variable name that I have been using like $_POST['confirm_delete'] then confirm_delete comes up as a suggestion if I type con.
Can I get this feature with eclipse?
Yes, Eclipse does have autocomplete. But not for unknown array indices like $_POST['myindex']. Autocomplete works for all your normal variables and classes/methods.
This might help : once you have already typed confirm_delete in your file somewhere, you can use eclipse's global autocomplete feature Alt + /. For example if you type con and Alt + / it will complete it with confirm_delete if it is the only word in the file that starts with "con" (otherwise type a few extra letters to be sure).
This works everywhere in the file, even in comments.
Eclipse (also Netbeans) cant auto complete array indexes.

closing php tag in string stops syntax highlighting

In my vim files, when I have a closing php tag in a string, my syntax highlighting stops at that point
Example:
<?php
... Everything good up to this point
$xml = '<?xml version="1.0"?>';
$foo = 'bar' <-- starting here I loose highlighting to the end of the file
?>
I'm running version 7.2.245. anyone have ideas why this happens? is it only me? or is this a known bug?
Make sure you have the latest version of the runtime files, or at least the very latest version of the php syntax file.
Try using this alternative syntax file instead.
It isnt a bug, you have actually ended the PHP string. you need to just break it up. Do like "'.'?'.'>' or something
This is normal. Notice the SO syntax highlighter stopped highlighting at that point too ;)
My windows editor does the same thing.
Even PHP's built in function works this way (or used to for a long time)

Categories