Correct indentation in array initialization, PDT / Zend Studio

I use the following array initialization style in code:

$a = array( 'one' => 123, 'two' => 456 ); 

But PDT / Zend Studio does not work properly in this case; after pressing the [Return] key, it places the cursor under $ a (in my example) and ignores the indent. If the keys of the array are numbers (at least they don't start with quotes), everything works fine.

Here's how it works now (| is the position where edtitor places the caret after pressing [Return])

 $a = array( 'one' => 123,[RETURN] | ); 

Expected Result:

 $a = array( 'one' => 123,[RETURN] | ); 

So is it possible to make the editor follow my nesting rules?

+7
php zend-studio eclipse-pdt
source share
7 answers

I recently had the exact same issue. I solved this in Zend Studio (Eclipse based IDE) by going to

Preferences -> PHP -> Code Style -> Formatter

and then select edit on the screen next to the presetter name. In the window that opens, go to the "Line Laying" tab and select

Expressions -> Array Initializers .

Play with the settings as you wish.

Hi

Lucas

+3
source share

In ZendStudio, you can apply PhpCodeFormatter using Ctrl + Shift + F.

Formatting can be configured in the window-> preferences-> PHP-> Code Style-> Formatter (Zend Studio 7.0) on reformat arrays, as described above.

PDT (as far as I know) does not have this feature.

+1
source share

I suggest you create an account in the bugzilla tracklist and vote for the following function:

https://bugs.eclipse.org/bugs/show_bug.cgi?id=320130

If there are enough people, they are likely to integrate such features into a future version of PDT.

+1
source share

I'm not sure about Eclipse, but I had the same problem in TextMate. I switched to soft tabs (aka 4 spaces) instead of tabs, and now it acts as "expected". Does ZendStudio have this option?

0
source share

@MGriesbach: Actually PDT (Eclipse) has this function (under Source-> Format)

@Sergei: Eclipse does not have this problem, but it sounds like something is wrong with your configuration. Are you sure you looked at all the options? You can also send an email to the Zend team, which sounds like a pretty commonplace mistake on the side of the heir, as it encourages developers to write indented code correctly.

- change -

My bad one has Eclipse PDT, but I'm just used to it :) The problem disappears if I click on the tab, so it will back off in the first line. Other lines will follow correctly.

0
source share

No, this is an Eclipse error.

I came across this using ALL Eclipse text editors (SQL, XML, YML, ShellEd and o).

However, this only happens with my installation of Eclipse for Linux (Kubuntu Karmic) on x86_64. I tested it on the i386 Karmic in my work and it works great.

0
source share

Try

Window-> Preferences
PHP-> Code Style-> Formatter
Indent → Dafal indentation for array initializers = 1

0
source share

All Articles