Separator in namespaces in PHP

    I recommend that you familiarize yourself with php internals: endnamespacediscussion

    After another discussion in IRC, it was decided to use the \ character as a separator in namespaces in PHP. The patch is being prepared, and it is not known whether it will go into PHP 5.3 or not.

    The argument can be found here or here.

    The main problem when using :: as a separator, according to the developers, is to understand what is happening in the line of code
    Foo::bar();

    it will become difficult (is it a call to the static bar () method from the Foo class or a call to the bar () function from the Foo namespace?). An additional limitation is the PHP interpreter itself, which cannot distinguish name resolution from calling a static method. It is supposed to get rid of such ambiguity using the \ character.


    However, many developers believe that this is the wrong choice. The \ character is used in escape sequences. There will be a problem with editing code in existing editors and IDEs, even just at the level of code highlighting, not to mention its analysis.

    The advantage of this approach, according to the developers of the patch, is that \ is used \ for \ separation \ elements \ paths in Windows and therefore will be intuitive for programmers from the Windows world (According to the results of the survey, most readers of php | architect work on Windows, and on Unix only deploy work :-)).

    Other pros are:
    1. \ visually differs from ::, and therefore, a quick look at the code will make it easier to distinguish the namespace from the static method
    2. \ is inserted into the code with just one per key (no need to pinch shift) in the English layout


    Also popular now: