开发者

PHP5.3 closures indentation in VIM

开发者 https://www.devze.com 2023-03-04 13:51 出处:网络
I have tried few different php indentation scripts, but they can\'t handle indentation of the following code:

I have tried few different php indentation scripts, but they can't handle indentation of the following code:

myfunc(function(){
    echo "hello";
    if(1==2){
        echo "world";
    }
});

Can you point out vimrc settings or php indentation file for vim which would handle new syntax of PHP5.3?

Update: Here is what I get:

myfunc(function(){
        echo "hello"开发者_高级运维;
        if(1==2){
        echo "world";
        }
        });

I use bundled indent for 7.3 from http://www.2072productions.com/vim/indent/php.vim John Wellesz

Remaining PHP syntax is indented correctly.


It may be because your closure syntax is incorrect. Closures shouldn't have names as far as I know. E.g. for a preg_replace_callback function, you'd either pass a variable containing a closure defined with function($matches){/* logic */} or the aforementioned code itself.

What you're trying to do here is define a function in a callback argument. BAAAAD for your script xD

Just get rid of the name like this and see if it helps:

myfunc(function(){
    echo "hello";
    if(1==2){
        echo "world";
    }
});

PHP docs show this syntax for closures too: http://php.net/manual/en/functions.anonymous.php

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号