2

I was reading the Unyson WP framework, they put some codes inside {} without any conditional statement!

https://github.com/ThemeFuse/Unyson/blob/master/framework/bootstrap.php

    include $fw_dir .'/bootstrap-helpers.php';

    /**
     * Load core
     */
    {
        require $fw_dir .'/core/Fw.php';
        fw();
    }

I checked the PHP docs and I didn't find anything about this! I think it's for lifetime management (memory management) but I'm not sure! Any help will be appreciated!

SuperDJ
  • 7,488
  • 11
  • 40
  • 74
Ali Aghdam
  • 25
  • 5
  • possible duplicate of [Use curly brackets to structure code in PHP](http://stackoverflow.com/questions/14971123/use-curly-brackets-to-structure-code-in-php) –  Aug 20 '15 at 09:57

1 Answers1

4

It doesn't affect memory management and is largely for structure and using code folding in editors.

As a bonus, it's also easy to exclude entire chunks by quickly adding if (false) in front.

Jason Spicer
  • 249
  • 1
  • 8
  • Thanks, Can you give me documentation link for more information!? – Ali Aghdam Aug 20 '15 at 12:20
  • What information would you like? When the code is compiled by the Zend engine, there's no additional opcodes generated as far as I can tell, so no memory difference. Code folding is supported by most editors to collapse chunks of code, that's certainly a convenience but it wouldn't be documented anywhere. As for excluding chunks, that's one of the big bonuses behind Allman style braces, an example of which is under https://en.wikipedia.org/wiki/Indent_style#Allman_style – Jason Spicer Aug 20 '15 at 13:56
  • Thank you for helping, One more question! This can affect performance? for example if i use it 50 time in my codes this can add overhead? – Ali Aghdam Aug 23 '15 at 14:53
  • If you use the braces like that in your code, it should not make any measurable difference to its performance. – Jason Spicer Aug 24 '15 at 07:43