Proper indentation in array initialization, PDT/Zend Studio
Asked Answered
U

7

7

I'm using the following style of array initialization in the code:

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

But PDT/Zend Studio doesn't work properly in this case; after pressing [Return] key it places cursor under the $a (in my example) and ignores indentation. If array keys are numbers (at least not start with quotation marks) everything is working fine.

This is how it works currently (| — is a position where edtitor places caret after pressing [Return])

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

This is expected result:

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

So is it possible to force editor follow my indentation rules?

Unclassified answered 27/8, 2009 at 5:7 Comment(6)
+1 : I've got exactly the same problem -- I indend the same way you do, and have never found a solution :-(Landpoor
Just an idea: what happens if you surround this with brackets? {$a = array( ... );}Loring
The same thing, no proper indentation.Unclassified
Have you looked through the code formatting settings in the configuration windows? I found them to be relatively detailed. If the setting is not there, I would file it as a bug.Idioblast
Yep, I've looked. There are no such thing, it realy looks like a bug.Unclassified
Same issue here, anyone that has a solution yet?Mablemabry
I
3

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

Preferences -> PHP -> Code Style -> Formatter

and then choose edit on the screen next to the fortmatter preset name. In the opened window go to the Line Wrapping tab and in the list choose

Expressions -> Array Initializers.

Play with the settings to your likings.

Regards

Lukas

Invoice answered 14/12, 2010 at 13:20 Comment(0)
C
1

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

The formatter can be configured in window->preferences->PHP->Code Style->Formatter (Zend Studio 7.0) to Reformat arrays as described above.

PDT, (as far as i know) does not have this function.

Curfew answered 27/8, 2009 at 9:27 Comment(0)
P
1

I suggest you to create a account in the bugzilla tracklist, and voting for the following feature:

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

If there is enough people, they probably integrate such functionalities in further version of PDT.

Prolix answered 11/10, 2010 at 23:10 Comment(1)
nice feature, left my vote, but I don't think that it'll be included because it's one of the primary features of Zend Studio.Unclassified
J
0

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 it now acts as "expected." Does ZendStudio have that option?

Janelljanella answered 27/8, 2009 at 21:18 Comment(2)
Strangely, I just opened up Flex Builder (also eclipse) and tested this and it works as expected. Something specific to Zend Studio? Maybe ask their support.Janelljanella
It looks like a PHP-bug (i.e. PDT, and Zend Studio is based on PDT).Unclassified
D
0

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

@Sergei: Eclipse doesn't have this problem, but this sounds like something is wrong with your config. Are you sure you looked through all the options? You may also send an email to the Zend team, this sounds like a pretty trivial bug on heir side, as it encourages developers to write code not indented correctly.

-- edit--

My bad, Eclipse PDT does have this problem but i just got used to it:) The problem dissapears if i press tab, so it will indent the first line. The other lines will follow correctly.

Durham answered 2/9, 2009 at 12:25 Comment(0)
E
0

No, that's Eclipse bug.

I've faced it using ALL the Eclipse text editors (SQL, XML, YML, ShellEd, and o on).

However, it happens only to my Eclipse installation for Linux (Kubuntu Karmic) on x86_64. I've tested it on i386 Karmic at my work and it works fine.

Elouise answered 26/4, 2010 at 0:43 Comment(0)
C
0

Try

Window->Preferences
PHP->Code Style->Formatter
Indentation->Dafault Indentation for array initializers = 1

Crabber answered 21/4, 2014 at 13:46 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.